问题
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