This project is read-only.

Can I return a data.frame from .Net to R?

Oct 23, 2013 at 9:47 PM
Edited Oct 23, 2013 at 10:28 PM
For example, I want to return an array of price/date pairs from a .Net method to R. Is that possible and what would it look like?
Oct 24, 2013 at 1:02 AM
Edited Oct 24, 2013 at 1:03 AM

Currently you'd need to arrange in your .NET language to create an array of DateTime and an array of doubles, retrieve them and create your data frame in R.

If you'd like to create a data frame whole in C# then return to R, this is something about to be supported. In practice with the current binaries released, this is probably not feasible.
I've had the same question yesterday.
I thought I would give it a try, using the latest changes I've made to rClr and R.NET over the past month.

The following code works as expected using the latest code at the new codeplex site fae1357cb5e3
clrGetStaticMethods("Rclr.RdotnetDataConverterTests" )
clrGetMemberSignature("Rclr.RdotnetDataConverterTests", "CreateTestDataFrame" )
df <- clrCallStatic("Rclr.RdotnetDataConverterTests", "CreateTestDataFrame" )
#  name a
#1    a 1
#2    b 2
#3    c 3
I'll design an API for more seamless data frame handling over the coming month. I cannot work on this much as part of my day job, so it may take a while. The API may look like this, but this is something I'd welcome suggestions on:
dotNetDictionary <- clrCallStatic ("TestClass", "CreateDictionary")  # something like Dictionary<string,Array>  
df <- )
dotDataSet <- clrCallStatic ("TestClass", "CreateDataSet")  # I have not used DataSet for years, but this is probably what people dealing with databases have in mind  
df <- )
dotGridView <- clrCallStatic ("TestClass", "CreateGridView")  # Again something I have lost touch with over the years.
df <- )
Oct 24, 2013 at 5:56 PM
Your proposed API looks good. I might suggest the DataTable class as a natural way to map to an R data.frame.

Dictionary seems narrow, and GridView and the full blown DataSet class seem heavy.

The Tuple class might be a light weight solution, though nested tuples would be required for data.frames wider than 8 columns (and no column naming).

Thank you for your work on this, I very much look forward to your new API for this.

Mar 5, 2015 at 9:40 AM
Thanks for a great library!
A seamless conversion from DataTable to DataFrame would indeed be very useful