Skip to content

Instantly share code, notes, and snippets.

@o7g8
Last active February 4, 2017 19:03
Show Gist options
  • Save o7g8/40a918bb7f6d4559689689582a8e140b to your computer and use it in GitHub Desktop.
Save o7g8/40a918bb7f6d4559689689582a8e140b to your computer and use it in GitHub Desktop.
F#: RProvider on Linux

F#: Making RProvider work on Linux (Lubuntu 16.04)

Here are the necessary steps:

  • Install the recent Mono including F# as it's described in the section Debian, Ubuntu, and derivatives.

  • Install Monodevelop (the addins are not necessary for RProvider, but are handy to have anyway):

sudo apt-get install monodevelop monodevelop-nunit monodevelop-versioncontrol
  • In the Monodevelop install the F# plugin (you can ignore the installation error, it's a known bug).

  • Restart the Monodevelop!

  • Skim through the guide Using R provider on Mac and Linux and ignore everything regarding the 64-bitness: Mono is 64bit on the Linux distribution by default.

  • Configure RProvider:

echo -e "MONO64=`which mono`\nR_HOME=`R --print-home`" > ~/.rprovider.conf
  • Create a F# Tutorial solution, as described in the guide mentionned above, and install rprovider nuget package.

  • Paste following code into the Tutorial.fsx (pay attention to the I path and the RProvider version):

#nowarn "211"
#I "../packages/RProvider.1.1.20"
#load "RProvider.fsx"

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

R.mean([1;2;3;4])

// 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)
  • Close the R graph window later with:
R.graphics_off()
  • If you want to run examples from R Provider Tutorial, you need to install some R packages. Run following commands in R command prompt:
install.packages("zoo")
install.packages("tseries")

Also replace SPX with SPY in the example F# code from the tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment