Can't read csv automatically with R(D)COM

7

I have a problem when trying to read .csv file with STATCONNECTORSRVLib (R(D)COM).

When I enter this code lines, it works:

    var sc1 = new STATCONNECTORSRVLib.StatConnector();
    sc1.Init("R");
    sc1.EvaluateNoReturn("dataset=read.csv(file.choose())");

A pop up windows is opened, I choose file from c:\\ , it loads, and I can do calculation with it.

However, when I enter this almost exact code:

    var sc1 = new STATCONNECTORSRVLib.StatConnector();
    sc1.Init("R");
    sc1.EvaluateNoReturn("dataset=read.csv('C:\\output.csv')");

I get this annoying exception:

"The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"

The line dataset=read.csv('C:\\output.csv') works fine in R console.

What am I doing wrong, and how can my machine read file when I'm uploading manualy, but not automaticly?

I'm using: R 2.13.1 from RandFriend pack, and have all that is included within it. OS Windows 7, 64 bit
All my projects in the solution are .NET 4, x86

c#
r
asked on Stack Overflow Aug 23, 2011 by Guy Segal • edited Aug 23, 2011 by Bo Persson

1 Answer

2

Not tested, but I think C# is treating converting your double backslashes to a single backslash, which R is then interpreting as an escape sequence. Try changing your string to

"dataset=read.csv('C:\\\\output.csv')"

or

@"dataset=read.csv('C:\\output.csv')"

or

"dataset=read.csv('C:/output.csv')"
answered on Stack Overflow Aug 23, 2011 by Richie Cotton

User contributions licensed under CC BY-SA 3.0