Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

r

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

like image 435
Guy Segal Avatar asked Aug 23 '11 11:08

Guy Segal


People also ask

How do I read a csv file in R studio?

In RStudio, click on the Workspace tab, and then on “Import Dataset” -> “From text file”. A file browser will open up, locate the . csv file and click Open.

Which function can be used to read CSV file in R?

csv() Function. read. csv() function in R Language is used to read “comma separated value” files. It imports data in the form of a data frame.

How do I open a CSV file in R?

If your CSV file is reasonably small, you can just use the read. csv function from Base R to import it. When using this method, be sure to specify stringsAsFactors=FALSE so that R doesn't convert character or categorical variables into factors.

Which package has read csv?

Reading in a . csv file is easy and is part of read. table in the R utils package (installed by default).


1 Answers

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')"
like image 147
Richie Cotton Avatar answered Sep 19 '22 05:09

Richie Cotton