Skip to content
hmansell edited this page Aug 1, 2012 · 10 revisions

Packages

How do I Load a Package?

RProvider discovers the packages installed in your R installation and makes them available as packages under the RProvider root namespace. The actual package is lazily loaded the first time you access it.

How do I install a new Package?

Currently you need to load up a real R session, then install the package via install.packages, or the Packages/Install Packages... menu. You will then need to restart Visual Studio because the set of installed packages is cached inside the RProvider.

I have a package installed and it is not showing up

The most likely cause is that RProvider is using a different R installation from the one you updated. When you install R, you get the option to update the registry key HKEY_LOCAL_MACHINE\SOFTWARE\R-core to point to the version you are installing. This is what RProvider uses. If you are running in a 32-bit process, RProvider uses HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R\InstallPath to determine the path. For 64-bit, it reads HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R64\InstallPath. When you install a package in a given version of R, it should be available in both the 32-bit and 64-bit versions.

Passing Parameters

Parameter Passing Conventions

R supports various kinds of parameters, which we try to map onto equivalent F# parameter types:

  • All R formal parameters have names, and you can always pass their values either by name or positionally. If you pass by name, you can skip arguments in your actual argument list. We simply map these onto F# arguments, which you can also pass by name or positionally.
  • In R, essentially all arguments are optional (even if no default value is specified in the function argument list). It's up to the receiving function to determine whether to error if the value is missing. So we make all arguments optional.
  • R functions support ... (varargs/paramarray). We map this onto a .NET ParamArray, which allows an arbitrary number of arguments to be passed. However, there are a couple of kinks with this:
    • R allows named arguments to appear after the ... argument, whereas .NET requires the ParamArray argument to be at the end. Some R functions use this convention because their primary arguments are passed in the ... argument and the named arguments will sometimes be used to modify the behavior of the function. From the RProvider you will to supply values for the positional arguments before you can pass to the ... argument. If you don't want to supply a value to one of these arguments, you can explicitly pass System.Reflection.Missing.
    • Parameters passed to the R ... argument can also be passed using a name. Those names are accessible to the calling function. Example are list and dataframe construction (R.list, and R.data_frame). To pass arguments this way, you can use the overload of each function that takes an IDictionary<string, obj>, either directly, or using the namedParams function. For example: R.data_frame(namedParams [ "A", [|1;2;3|]; "B", [|4;5;6|] ])

Clone this wiki locally