exception unhandled in Reading data

Dec 4, 2013 at 2:31 AM
Hello
Thank you for the wonderful middle ware R.NET.
I am trying to let R read data
My VB. net code is:
Dim charVec As CharacterVector = engine.CreateCharacterVector(New String() {"low_train.csv"})
          engine.SetSymbol("filename", charVec)
           engine.Evaluate("dataset<-read.table(filename, header=TRUE, sep = ',')")
I got the error
ParseException was unhandled

Any idea how to solve this
Thanks
Developer
Dec 5, 2013 at 2:32 AM
ParseException is thrown when the native R engine returned an error code to R.NET. Unfortunately there is no more details as to what goes wrong coming from the R dll.

Can you give the whole code sample that reproduces your error, but in a form as conncise as possible? you do not include the initialisation phase. Also can you give more information as the machine and software versions you are using.
Dec 5, 2013 at 11:46 PM
Edited Dec 5, 2013 at 11:47 PM
Thank you jperraud

the code is
Imports RDotNet
Imports RDotNet.NativeLibrary
.....
...
..
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim oldPath = System.Environment.GetEnvironmentVariable("PATH")
    Dim rPath = If(System.Environment.Is64BitProcess, "C:\Program Files\R\R-3.0.2\bin\x64", "C:\Program Files\R\R-3.0.2\bin\i386")
    Dim newPath = String.Format("{0}{1}{2}", rPath, System.IO.Path.PathSeparator, oldPath)
    System.Environment.SetEnvironmentVariable("PATH", newPath)
    Using engine As REngine = REngine.CreateInstance("RDotNet")
        engine.Initialize()
        Dim file_name As String = "low_train.csv"
       Dim charVec As CharacterVector = engine.CreateCharacterVector(New String() {"low_train.csv"})
       engine.SetSymbol("filename", charVec)
       engine.Evaluate("str(filename)")
        engine.Evaluate("dataset<-read.csv(filename, header=TRUE, sep = ',')")   
        End Using
        End Sub
the code that gives exception is engine.Evaluate("dataset<-read.csv(filename, header=TRUE, sep = ',')")

simply what i want to do is let R read file that contains data, the file name is low_train.csv

I am using win7, 64
R 64
visual studio 2013
R.NET 1.5.5

Thank you again
Developer
Dec 6, 2013 at 9:44 PM
I suspect you get this exception if you click twice on your button. Such issues have been reported, and are expected since the R engine must not be initialized twice in the same process.
The following code works just fine for me with R.NET 1.5.5 as currently downloadable. Note the use of a single pattern to initialize the engine once even if CreateSingleton is called twice. See at the bottom of https://rdotnet.codeplex.com/discussions/453270 for more information on the singleton pattern.
Imports RDotNet

Module Module1

    Dim engine As REngine = Nothing

    Sub Main()
        CreateSingleton()
        DoCalc()
        DoCalc()
    End Sub

    Sub CreateSingleton()
        If (engine Is Nothing) Then
            Dim oldPath = System.Environment.GetEnvironmentVariable("PATH")
            Dim rPath = If(System.Environment.Is64BitProcess, "C:\Program Files\R\R-3.0.2\bin\x64", "C:\Program Files\R\R-3.0.2\bin\i386")
            Dim newPath = String.Format("{0}{1}{2}", rPath, System.IO.Path.PathSeparator, oldPath)
            System.Environment.SetEnvironmentVariable("PATH", newPath)
            engine = REngine.CreateInstance("RDotNet")
            engine.Initialize()
        End If

    End Sub

    Sub DoCalc()
        Dim file_name As String = "c:\tmp\test.csv"
        Dim charVec As CharacterVector = engine.CreateCharacterVector(New String() {file_name})
        engine.SetSymbol("filename", charVec)
        engine.Evaluate("str(filename)")
        engine.Evaluate("dataset<-read.csv(filename, header=TRUE, sep = ',')")
        Dim somevalues = engine.Evaluate("dataset$a").AsInteger().ToArray()
    End Sub

End Module
Dec 9, 2013 at 12:20 AM
Thank you very much
Your solution is very useful
problem solved