3

I have a C# application which needs a Deedle Frame as input data. I also have a R script that return a data frame, and I don't want to re-implement the algorithm in R script by C#. I tried using R.Net, I can get the data frame from R script in C# application, but its type is RDotNet.DataFrame. Is there any to convert RDotNet.DataFrame to Deedle Frame in C# code?

I am also thinking about creating a F# dll library that calls the R script, then use that dll library in C# code. Is it possible?

Ha Pham
  • 373
  • 3
  • 18

1 Answers1

1

If you use Deedle from F#, then you can also use the R type provider. The two are nicely integrated and you can call R from F# and get back a Deedle data frame. There is a good example on this in the Deedle documentation.

R provider will automatically turn R data frames into Deedle frames. For example:

open RProvider.datasets

// Get mtcars as a typed Deedle frame
let mtcars : Frame<string, string> = R.mtcars.GetValue()

The source code that does the conversion in R provider and Deedle is available too. So if you wanted to use it directly, the place to start is the tryCreateFrame function in Deedle source code.

This is not really exposed to C# at this point, but we would certainly welcome a pull request making this possible for Deedle :-).

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • I can use F# to get the Frame returned by R script now. But how to send a Deedle Frame to the R script. I want to build an app that receive and Deedle Frame as input data, do something data processing, then return a Deedle Frame as the output data – Ha Pham Oct 15 '15 at 04:36
  • This should work automatically with R provider too. Whenever you pass Deedle frame to a function exported by R provider, it will be automatically converted to R frame. See: http://bluemountaincapital.github.io/Deedle/rinterop.html#From-Deedle-to-R – Tomas Petricek Oct 15 '15 at 12:13
  • When I run this line of code `R.assign("dataframe", frame) `, _frame_ is a Deedle.Frame, i see that it also print the data frame to console screen. But when I run this `R.assign("text",text)`, _text_ is a text string, it doesn't print anything. And `let frame : Frame = result.GetValue()`, this line of code also prints the data. So I think the converter between Deedle.Frame and R Frame does print the data. Is there any way to avoid it? – Ha Pham Oct 20 '15 at 10:08