fslaborg / Deedle

Easy to use .NET library for data and time series manipulation and for scientific programming
http://fslab.org/Deedle/
BSD 2-Clause "Simplified" License
933 stars 195 forks source link

C# Deedle.Rplugin R Dataframe to Deedle.Frame #267

Closed sonderak closed 9 years ago

sonderak commented 10 years ago

Hello! I am trying to read a dataframe from the Rdotnet environment in C# into Deedle.Frame without having to be specific about Types TRowKey and TColumnKey, since dynamically I may not know the types.

I tried

var temp  = RInterop.defaultFromR(engine.GetSymbol(Rvarname).AsDataFrame());
//Rvarname is a dataframe in R environment

In order to convert this to Frame, I tried -

Type ftype = temp.GetType();
Frame< ftype.GetGenericArguments()[0], ftype.GetGenericArguments()[1] > dframe = new Frame<....>()

But this does not work since the GenericArguments() are not available. Could you please suggest a way to achieve this without having to sort to using specific Deedle.Rplugin classes like DataFrameStringStringFromR, DataFrameIntStringFromR etc... ?

Eventually I would like to show the R dataframe in a datagridview.

Thank you.

tpetricek commented 9 years ago

Doing this generically is tricky, but in general, when you have an R value like temp, you can either call:

temp.Value
temp.GetValue<Frame<string, string>>()

The first one gives you obj which is Frame<R, C> and you could use reflection on this to find out what is the row/column key. The second one gives you a frame of a specified type.