Writing a csv file in R from Java using JRI

廉价感情. 提交于 2020-01-17 08:31:21

问题


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)

回答1:


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.



来源:https://stackoverflow.com/questions/7469260/writing-a-csv-file-in-r-from-java-using-jri

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!