0

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)
3
  • Please tell us what did happen. That makes it much easier to diagnose the problem. Commented Sep 19, 2011 at 12:34
  • It says: Error: '\D' is an unrecognized escape in character string starting "C:\D" The code does work in R Commented Sep 19, 2011 at 13:17
  • In that case, try "C:\\D" to escape the escape sequence. This is a common gotcha in bash scripting; I'm not expert enuff in Java to know where the command parsing takes place. Commented Sep 19, 2011 at 17:00

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.