0

I'm trying to implement my R script on vb.NET using Rdotnet. First, I call SQL stored procedure from my database to perform some pre-processing of the data. This gives me a DataTable object in vb.NET. Then, I intend to run my R function using Rdotnet for further processing. Since my R script can only read dataframe object, I try to create a dataframe object using the CreateDataFrame function in Rdotnet. Forgive me, but I am not able to provide the actual data due to the sensitive nature of the data.

Public Function Detect_Gridlock(ByVal data As DataTable)
    Dim engine As REngine = REngine.GetInstance()
    engine.Initialize()
    Dim columns As IEnumerable = data.Columns
    Dim tableDF As DataFrame = engine.CreateDataFrame(columns, colList(data))
    Return tableDF
End Function

Public Function colList(ByVal data As DataTable)
    Dim colNames(data.Columns.Count) As String
    Dim i As Integer = 1
    For Each column As DataColumn In data.Columns
        colNames(i) = column.ColumnName
    Next
    Return colNames

End Function

Which gives me an error message : Unable to cast object of type 'System.Data.DataColumnCollection' to type 'System.Collections.IEnumerable[]'.

Although my column data in columns and colList(data) which are the column names are in the form of collection.

Thank you

1 Answers1

0

Maybe you could use

Dim columns() as IEnumerable 
Dim tableDF As DataFrame = engine.CreateDataFrame(columns.Cast(Of IEnumerable()), colList(data))

instead of

Dim columns as IEnumerable
Dim tableDF As DataFrame = engine.CreateDataFrame(columns, colList(data))

The problem here is that the first argument is an ARRAY of IEnumerables, which you got confused. However I do not know how to get the data.Columns to return an Array of IEnumerables.