Requirements: Getting Started

The R type provider can be used on macOS, Windows, and Linux (for supported OS versions, see the .NET 5 OS support matrix).

There are three requirements to use the R type provider:

  • dotnet SDK 5.0 or greater; and
  • R statistical environment.
  • A correctly set R_HOME environment variable (see below). You must set the R_HOME environment variable to the R home directory, which can usually be identified by running the command 'R RHOME'.

Note. If you require .NET framework / mono support, you should use RProvider 1.2 or earlier. Support for .NET versions below 5.0 was dropped with RProvider 2.0.

Setting the R_HOME environment variable

The R type provider requires that the R_HOME environment variable is set, so that it can find the R installation that you wish to use.

macOS

In a Terminal window, execute the following command to add the R_HOME environment variable permanently:

echo export R_HOME=$(R RHOME) >> ~/.zshenv

Linux

You can set the R_HOME environment variable in your current session using the command:

export R_HOME=$(R RHOME)

Windows

On Windows, from a command prompt use the following command to set the R_HOME permanently as a user environment variable, replacing C:\rpath\bin with your R install location:

setx R_HOME "C:\rpath\bin"

Testing the R provider

You can now start experimenting with the R type provider using your favourite editor, or directly from the command line using

dotnet fsi

The easiest way to get started is to install Visual Studio Code, making sure to also install the Ionide-fsharp extension within the Extensions tab.

First, create a new file with the extension .fsx (e.g., test.fsx). Second, reference the R type provider package from NuGet by adding this line to the start of your file:

#r "nuget: RProvider,2.0.2"

Third, add your code. In this code, we load RProvider, then load three R packages using the open declarations (graphics, grDevices, and datasets).

open RProvider
open RProvider.graphics
open RProvider.grDevices
open RProvider.datasets

Now we can run some calculations and create charts. When using R on Mac, the default graphics device (Quartz) sometimes hangs, but X11 is working without issues, so the following uses X11:

// basic test if RProvider works correctly
R.mean([1;2;3;4])
// val it : RDotNet.SymbolicExpression = [1] 2.5
// testing graphics
R.x11()
// Calculate sin using the R 'sin' function
// (converting results to 'float') and plot it
[ for x in 0.0 .. 0.1 .. 3.14 -> 
    R.sin(x).GetValue<float>() ]
|> R.plot

// Plot the data from the standard 'Nile' data set
R.plot(R.Nile)

Diagnostics and debugging

If you encounter any issues, please do not hesitate to submit an issue! You can do that on the GitHub page. Before submitting an issue, please see the Diagnostics and debugging page, which tells you how to create a log file with more detailed information about the issues.

namespace RProvider
Multiple items
namespace RProvider

--------------------
type RProvider = inherit TypeProviderForNamespaces new : cfg:TypeProviderConfig -> RProvider

--------------------
new : cfg:CompilerServices.TypeProviderConfig -> RProvider
namespace RProvider.graphics
namespace RProvider.grDevices
namespace RProvider.datasets
type R = static member ! :?paramArray: obj [] -> SymbolicExpression + 2 overloads static member != :?paramArray: obj [] -> SymbolicExpression + 2 overloads static member !_hexmode :?a: obj -> SymbolicExpression + 2 overloads static member !_octmode :?a: obj -> SymbolicExpression + 2 overloads static member $ :?paramArray: obj [] -> SymbolicExpression + 2 overloads static member $<- :?paramArray: obj [] -> SymbolicExpression + 2 overloads static member $<-_data_frame :?x: obj *?name: obj *?value: obj -> SymbolicExpression + 2 overloads static member $_DLLInfo :?x: obj *?name: obj -> SymbolicExpression + 2 overloads static member $_package__version :?x: obj *?name: obj -> SymbolicExpression + 2 overloads static member %% :?paramArray: obj [] -> SymbolicExpression + 2 overloads ...
Base R functions.
R.mean(paramsByName: List<string * obj>) : RDotNet.SymbolicExpression
R.mean(paramsByName: System.Collections.Generic.IDictionary<string,obj>) : RDotNet.SymbolicExpression
R.mean(?x: obj,?___: obj,?paramArray: obj []) : RDotNet.SymbolicExpression
Arithmetic Mean
type R = static member CIDFont :?family: obj *?cmap: obj *?cmapEncoding: obj *?pdfresource: obj -> SymbolicExpression + 2 overloads static member Type1Font :?family: obj *?metrics: obj *?encoding: obj -> SymbolicExpression + 2 overloads static member X11 :?display: obj *?width: obj *?height: obj *?pointsize: obj *?gamma: obj *?bg: obj *?canvas: obj *?fonts: obj *?family: obj *?xpos: obj *?ypos: obj *?title: obj *?type: obj *?antialias: obj *?symbolfamily: obj -> SymbolicExpression + 2 overloads static member X11Font :?font: obj -> SymbolicExpression + 2 overloads static member X11Fonts :?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member X11_options :?___: obj *?reset: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member adjustcolor :?col: obj *?alpha_f: obj *?red_f: obj *?green_f: obj *?blue_f: obj *?offset: obj *?transform: obj -> SymbolicExpression + 2 overloads static member as_graphicsAnnot :?x: obj -> SymbolicExpression + 2 overloads static member as_raster :?x: obj *?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member axisTicks :?usr: obj *?log: obj *?axp: obj *?nint: obj -> SymbolicExpression + 2 overloads ...
Graphics devices and support for base and grid graphics.
R.x11(paramsByName: List<string * obj>) : RDotNet.SymbolicExpression
R.x11(paramsByName: System.Collections.Generic.IDictionary<string,obj>) : RDotNet.SymbolicExpression
R.x11(?display: obj,?width: obj,?height: obj,?pointsize: obj,?gamma: obj,?bg: obj,?canvas: obj,?fonts: obj,?family: obj,?xpos: obj,?ypos: obj,?title: obj,?type: obj,?antialias: obj,?symbolfamily: obj) : RDotNet.SymbolicExpression
X Window System Graphics (X11)
val x : float
R.sin(paramsByName: List<string * obj>) : RDotNet.SymbolicExpression
R.sin(paramsByName: System.Collections.Generic.IDictionary<string,obj>) : RDotNet.SymbolicExpression
R.sin(?paramArray: obj []) : RDotNet.SymbolicExpression
No documentation available
Multiple items
val float : value:'T -> float (requires member op_Explicit)
<summary>Converts the argument to 64-bit float. This is a direct conversion for all primitive numeric types. For strings, the input is converted using <c>Double.Parse()</c> with InvariantCulture settings. Otherwise the operation requires an appropriate static conversion method on the input type.</summary>
<param name="value">The input value.</param>
<returns>The converted float</returns>


--------------------
[<Struct>] type float = System.Double
<summary>An abbreviation for the CLI type <see cref="T:System.Double" />.</summary>
<category>Basic Types</category>


--------------------
type float<'Measure> = float
<summary>The type of double-precision floating point numbers, annotated with a unit of measure. The unit of measure is erased in compiled code and when values of this type are analyzed using reflection. The type is representationally equivalent to <see cref="T:System.Double" />.</summary>
<category index="6">Basic Types with Units of Measure</category>
type R = static member Axis :?x: obj *?at: obj *?___: obj *?side: obj *?labels: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member abline :?a: obj *?b: obj *?h: obj *?v: obj *?reg: obj *?coef: obj *?untf: obj *?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member arrows :?x0: obj *?y0: obj *?x1: obj *?y1: obj *?length: obj *?angle: obj *?code: obj *?col: obj *?lty: obj *?lwd: obj *?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member assocplot :?x: obj *?col: obj *?space: obj *?main: obj *?xlab: obj *?ylab: obj -> SymbolicExpression + 2 overloads static member axTicks :?side: obj *?axp: obj *?usr: obj *?log: obj *?nintLog: obj -> SymbolicExpression + 2 overloads static member axis :?side: obj *?at: obj *?labels: obj *?tick: obj *?line: obj *?pos: obj *?outer: obj *?font: obj *?lty: obj *?lwd: obj *?lwd_ticks: obj *?col: obj *?col_ticks: obj *?hadj: obj *?padj: obj *?gap_axis: obj *?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member axis_Date :?side: obj *?x: obj *?at: obj *?format: obj *?labels: obj *?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member axis_POSIXct :?side: obj *?x: obj *?at: obj *?format: obj *?labels: obj *?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member barplot :?height: obj *?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads static member barplot_default :?height: obj *?width: obj *?space: obj *?names_arg: obj *?legend_text: obj *?beside: obj *?horiz: obj *?density: obj *?angle: obj *?col: obj *?border: obj *?main: obj *?sub: obj *?xlab: obj *?ylab: obj *?xlim: obj *?ylim: obj *?xpd: obj *?log: obj *?axes: obj *?axisnames: obj *?cex_axis: obj *?cex_names: obj *?inside: obj *?plot: obj *?axis_lty: obj *?offset: obj *?add: obj *?ann: obj *?args_legend: obj *?___: obj *?paramArray: obj [] -> SymbolicExpression + 2 overloads ...
R functions for base graphics.
Multiple items
R.plot(paramsByName: List<string * obj>) : RDotNet.SymbolicExpression
R.plot(paramsByName: System.Collections.Generic.IDictionary<string,obj>) : RDotNet.SymbolicExpression
R.plot(?x: obj,?y: obj,?___: obj,?paramArray: obj []) : RDotNet.SymbolicExpression
No documentation available

--------------------
R.plot(paramsByName: List<string * obj>) : RDotNet.SymbolicExpression
R.plot(paramsByName: System.Collections.Generic.IDictionary<string,obj>) : RDotNet.SymbolicExpression
R.plot(?x: obj,?y: obj,?___: obj,?paramArray: obj []) : RDotNet.SymbolicExpression
Generic X-Y Plotting
type R = static member AirPassengers : SymbolicExpression static member BJsales : SymbolicExpression static member BJsales_lead : SymbolicExpression static member BOD : SymbolicExpression static member CO2 : SymbolicExpression static member ChickWeight : SymbolicExpression static member DNase : SymbolicExpression static member EuStockMarkets : SymbolicExpression static member Formaldehyde : SymbolicExpression static member HairEyeColor : SymbolicExpression ...
Base R datasets.
property R.Nile: RDotNet.SymbolicExpression with get