R Type Provider


Using R provider on Mac and Linux

The most recent version of the R type provider can be used on Mac and Linux using Mono. However, there is a bit of setup that you need to go through first. This document describes the necessary steps for using R provider on Mac using Xamarin Studio, but it should be easily adaptable for other configuration. If no, please edit this file to add more details!

In summary, you need the following:

  • Download and build 64 bit version of Mono, because the default installation is 32 bit and R provider only works with 64 bit version.
  • Tell Xamarin Studio to run 64 bit version of F# Interactive (the main IDE will still run as 32 bit, which is fine).
  • Create a file ~/.rprovider.conf with configuration that tells R provider where to find 64 bit version of mono.

This page is based on this excellent write-up on running R.NET on Mac by Evelina Gabasova. The page has some more details and hints that you may need if the simplified version below does not work for you.

Installing 64 bit version of Mono

First of all, you need 64 bit version of Mono. To do this, you'll need command line tools autoconf, automake and libtool. Probably the easiest way to do this is to install Homebrew (but feel free to use your favorite tool) and then run:

1: 
2: 
3: 
brew install automake
brew install autoconf
brew install libtool

Now you can use git to get the latest version of Mono from GitHub and install it. The following installs it into /usr/local/mono64 (feel free to change this too):

1: 
2: 
3: 
4: 
5: 
6: 
export MONO_PREFIX=/usr/local/mono64
git clone https://github.com/mono/mono.git
cd mono
./autogen.sh --prefix=$MONO_PREFIX --disable-nls  
make
make install

You might get a timeout from git when running the autogen-command, if you are behind a firewall. To fix this just run the following, which will force git to clone using "https://" instead of "git://":

1: 
git config --global url."https://".insteadOf git://

Now we can run Mono in 64-bit explicitly using /usr/local/mono64/bin/mono. Next, we need to create a launcher script that will start F# Interactive in 64 bit.

Running F# Interactive in 64 bit

The F# Interactive launcher that comes with standard installation of Mono is fsharpi. On Mac, you can find it (depending on your Mono version) in a folder like /Library/Frameworks/Mono.framework/Versions/3.4.0/bin/.

Create a copy of this file called, for example, fsharpi64 (in the same folder) and change the bit that points to the Mono installation, so that it points to the newly installed 64 bit version. Also, change fsi.exe to fsiAnyCpu.exe at the end. The whole thing should be on a single line, but the following shows it with newlines for better readability:

1: 
2: 
3: 
4: 
$EXEC /usr/local/mono64/bin/mono  
    $DEBUG $MONO_OPTIONS 
    /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.0/fsiAnyCpu.exe 
    --exename:$(basename $0) "$@"

When you start Xamarin Studio, you can now tell it to use fsharpi64 instead of fsharpi. To do this, go to Preferences > Other > F# Settings > F# interactive. Once you change this, you can test which version of F# Interactive you're running by entering System.IntPtr.Size (if the result is 4, you're running 32 bit; if the result is 8, you're on a 64 bit).

Configuring R provider

Finally, you need to tell the R provider where to find the 64 bit installation on Mono (the R provider starts a background process to communicate with R using the 64 bit version). To do that, create a file ~/.rprovider.conf (that is, in your home folder) containing a single line MONO64=/usr/local/mono64/bin/mono.

You can create the file using the following command:

1: 
echo MONO64=$MONO_PREFIX/bin/mono > ~/.rprovider.conf

And this is all you should need! One more thing to check is to make sure that R is in your PATH (and the R provider will be able to find it). To do that, open Terminal and type R --print-home. This command should print the home folder and is used by the R type provider.

If calling R --print-home does not work, you'll need to create an environment variable R_HOME and point it to the R home folder. On Mac, this is something like /Library/Frameworks/R.framework/Resources (check that $R_HOME/lib/libR.dylib exists).

Testing the R provider

Now you can open Xamarin studio and start playing with the R type provider. The easiest way to do that is to create a new F# Tutorial, add a new file (say Test.fsx) and reference R provider using NuGet (right click on the project Add > Add Packages... and search for "rprovider").

Now, type the following in the script file (with the correct R provider version):

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
#nowarn "211"
#I "packages/RProvider.1.1.4"
#load "RProvider.fsx"

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

The #load command loads the R provider. The first line disables warnings about unnecessary folder references (a few are generated by the loader script). Finally, the open declarations open a number of standard R packages.

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:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
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
namespace RProvider.graphics
namespace RProvider.grDevices
namespace RProvider.datasets
type R =
  static member CIDFont : ?family: obj * ?cmap: obj * ?cmapEncoding: obj * ?pdfresource: obj -> SymbolicExpression + 1 overload
  static member Hershey : SymbolicExpression
  static member Type1Font : ?family: obj * ?metrics: obj * ?encoding: obj -> SymbolicExpression + 1 overload
  static member X11 : ?width: obj * ?height: obj * ?pointsize: obj * ?bg: obj * ?gamma: obj * ?xpos: obj * ?ypos: obj * ?title: obj -> SymbolicExpression + 1 overload
  static member adjustcolor : ?col: obj * ?alpha_f: obj * ?red_f: obj * ?green_f: obj * ?blue_f: obj * ?offset: obj * ?transform: obj -> SymbolicExpression + 1 overload
  static member as_graphicsAnnot : ?x: obj -> SymbolicExpression + 1 overload
  static member as_raster : ?x: obj * ?___: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member axisTicks : ?usr: obj * ?log: obj * ?axp: obj * ?nint: obj -> SymbolicExpression + 1 overload
  static member bitmap : ?file: obj * ?type: obj * ?height: obj * ?width: obj * ?res: obj * ?units: obj * ?pointsize: obj * ?taa: obj * ?gaa: obj * ?___: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member blues9 : SymbolicExpression
  ...

Full name: RProvider.grDevices.R


Graphics devices and support for base and grid graphics.
R.x11(paramsByName: System.Collections.Generic.IDictionary<string,obj>) : RDotNet.SymbolicExpression
R.x11(?width: obj, ?height: obj, ?pointsize: obj, ?bg: obj, ?gamma: obj, ?xpos: obj, ?ypos: obj, ?title: obj) : RDotNet.SymbolicExpression


No documentation available
val x : float
type R =
  static member ! : ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member != : ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member !_hexmode : ?a: obj -> SymbolicExpression + 1 overload
  static member !_octmode : ?a: obj -> SymbolicExpression + 1 overload
  static member $ : ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member $<- : ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member $<-_data_frame : ?x: obj * ?name: obj * ?value: obj -> SymbolicExpression + 1 overload
  static member $_DLLInfo : ?x: obj * ?name: obj -> SymbolicExpression + 1 overload
  static member $_data_frame : ?x: obj * ?name: obj -> SymbolicExpression + 1 overload
  static member $_package__version : ?x: obj * ?name: obj -> SymbolicExpression + 1 overload
  ...

Full name: RProvider.R


Base R functions.
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)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
type R =
  static member Axis : ?x: obj * ?at: obj * ?___: obj * ?side: obj * ?labels: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member abline : ?a: obj * ?b: obj * ?h: obj * ?v: obj * ?reg: obj * ?coef: obj * ?untf: obj * ?___: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  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 + 1 overload
  static member assocplot : ?x: obj * ?col: obj * ?space: obj * ?main: obj * ?xlab: obj * ?ylab: obj -> SymbolicExpression + 1 overload
  static member axTicks : ?side: obj * ?axp: obj * ?usr: obj * ?log: obj * ?nintLog: obj -> SymbolicExpression + 1 overload
  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 * ?___: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member axis_Date : ?side: obj * ?x: obj * ?at: obj * ?format: obj * ?labels: obj * ?___: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member axis_POSIXct : ?side: obj * ?x: obj * ?at: obj * ?format: obj * ?labels: obj * ?___: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  static member barplot : ?height: obj * ?___: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  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 * ?args_legend: obj * ?___: obj * ?paramArray: obj [] -> SymbolicExpression + 1 overload
  ...

Full name: RProvider.graphics.R


R functions for base graphics.
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
  ...

Full name: RProvider.datasets.R


Base R datasets.
property R.Nile: RDotNet.SymbolicExpression
Fork me on GitHub