Search code examples
javarrenjin

In Renjin, trying to write R script without losing the quotations


Let's say that I have the following Java code, using Renjin to run R on the JVM:

ScriptEngineManager manager = new ScriptEngineManager();
// create a Renjin engine:
ScriptEngine engine = manager.getEngineByName("Renjin");

I want to evaluate the following R code using Renjin:

analysis.time<-format(Sys.time(), "%a %b %d %X %Y")

To do this, I have this Java Code using Renjin:

engine.eval("analysis.time<-format(Sys.time(), "%a %b %d %X %Y")");

However, because of the quotes around %a %b %d %X %Y , my code is broken up in two parts. How can I write this to keep it consistent?

Thank you!


Solution

  • You can use an escape character (a backslash (\)) in front of the quotes that are part of "%a %b %d %X %Y".