Aran Brady
Aran Brady

Reputation: 139

Writing a csv file in R from Java using JRI

Apologies in advance if this is obvious, but I can't seem to find an answer to it online. I was wondering if it is possible to write to a csv file in R from Java. For example, if I was to create normal data and write it to a csv file, I thought something like this might work:

Rengine re=new Rengine(args, false, new TextConsole());
re.eval("write.csv(rnorm(100,50,10), file='C:\\MyDocuments\\test.csv')")

Also, on a lesser note, if I create an object in R from java, is there any way to access it later? A simple example:

re.eval(x<-20)
re.eval(x<-x+40)

Upvotes: 0

Views: 1267

Answers (1)

Aran Brady
Aran Brady

Reputation: 139

As Carl mentions above, this has to do with the escape character "\". I had tried "\\" as you would in java, however, R also needs to escape the escape sequence; this is where I was getting caught. In the end 6 backslashes were needed.

Upvotes: 2

Related Questions