Transfer data into a DataFrame‏

Apr 21, 2015 at 3:07 PM

I am trying to transfer a complex array into a DataFrame via rClr during an interactive R session in RGui on Windows.

I have already some C# code that executes a query and packages the resulting data as class to be passed to R.Net. The object that was created has the relevant source data to work with R.Net's CreateDataFrame method, i.e. the following works just fine in an EXE:

QueryResult queryResult = new QueryResult();
loader.Query(query, queryResult);
DataFrame dataFrame = engine.CreateDataFrame(queryResult.columnData, queryResult.columnName, null, false, true, false);
engine.SetSymbol(symbolName, dataFrame);

after this the "engine" instance knows about 'symbolName' as a DF and I can execute R code against it.

Now I am trying to call the same methods from R using rClr. The following code already works:
Loading the dynamic library for Microsoft .NET runtime...
Loaded Common Language Runtime version 4.0.30319.34209

loader <- clrNew("Loader", "dataSource");
query <- 'dataQuery'
result <- clrCall(loader, "Query", query)
An object of class "cobjRef"
Slot "clrobj":
<pointer: 0x000000002a72a7d0>
Slot "clrtype":
[1] "QueryResult"
[1] "columnData" "columnInputBaseType" "columnInputType"
[4] "columnInputWasNullable" "columnName" "columnOutputType"
I just don't understand how to get to a DataFrame from my data (or alternatively, how to get the current "engine" instance in my C# method). Any help would be appreciated!
May 20, 2015 at 7:19 AM
The question was answered via email, but @ferzkopp2 kindly re-posted here for general use

You are on the right track, and visibly already gave a good think about it.

A working example that I have and use for project work is the method AsDataFrame in
This is not a small sample code, but I hope this will illustrate how to you can do that.
The R code that uses this function is in has a readme, if you are interested in exploring the package further.