Access Thousands of R Statistics Packages from F# 3.0

Did you know you can use F# type providers to access thousands of statistical packages from R, with auto-complete and documentation?

Those of you into data analysis will be aware of the use of the R system by statisticians and other data workers.

The F# community and BlueMountain Capital have created a type provider for F#-R interop which embeds all installed R packages directly into F#, with intellisense.  See the  example below. 

This demonstrates the great flexibility and applicability of the F# 3.0 type provider mechanism, for interoperating with everything from internet-scale information services to traditional SQL programming to interoperating with other programming environments.   

You can also join in the fun and contribute/fork the project on GitHub.


Announcing the F# R Type Provider

August 1, 2012 at 2:52 pm

Here at BlueMountain we like to perform statistical analysis of data.  The stats package R is great for doing that.  We also like to use the data retrieval and processing capabilities of F#. F#’s interactive environment lends itself pretty well to data exploration, and we can also easily access our existing .NET-based libraries.  Once we are done, we can build and release production-supportable applications.

Nothing on the .NET platform competes with R for statistical functionality, so we set about bridging the gap between F# and R.  F# 3.0 provides a nice innovative mechanism for doing this, through Type Providers.

We have released an Open Source RProvider on github.  Here’s an example of how to use it:

// Pull in stock prices for some tickers then compute returns let data = [ for ticker in [ "MSFT"; "AAPL"; "VXX"; "SPX"; "GLD" ] -> ticker, getStockPrices ticker 255 |> R.log |> R.diff ] // Construct an R data.frame then plot pairs of returns let df = R.data_frame(namedParams data) R.pairs(df)

Any of the calls above that begin R. are actually evaluated inside the R engine.

This produces a lovely pair plot like this:

While we intend to continue to enhance the provider to meet our needs, we really hope others will do the same.  If you use F# and work in the statistical/econometrics space, please try it out.  If you use R and are looking for a robust environment in which to develop applications, also try it (and F#) out.  If you have ideas for improvements, please feel free to share them with us.  And if you develop enhancements/fixes, please submit a pull request!

The RProvider is built on the RDotNet project, which handles all the gnarly interop with unmanaged data structures used by R.DLL.  The Type Provider provides an easy-to-use layer on top of that to use R from F#.  Many thanks go to the RDotNet author, Kosei.


Comments (6)

  1. Doug Finke says:

    This is great. Can you use the RProvider from C#?

    [ Don says – no, C# doesn't support type providers ]

  2. Nicolas says:

    Tested it today, I can finally massage data from Bloomberg with my favorite langage and use the amazing R.

    The type provider code itself is very clean and well written.

  3. Faisal Waris says:

    For someone working in the analytics area, this is fantastic news! Can't wait to try it out.

  4. Eugen Hotwagner says:

    Great, i was thinking exactly about this for some time.

    Now, where is the type provider for Mathematica 🙂

  5. Niel says:

    Very great news! I'm currently using R.NET with c# for finance and portfolio optimization.  Thought about implementing something like websharper (using R as target language instead of javascript) in f#.  This saves me lot of time and headaches! Great work and thanx to all involved!

  6. Seth says:

    Is this available in a F# worker role in azure?

Skip to main content