Passing a string argument when running R script from command line

Hello, everyone

In top of my R script file, I add

for (arg in commandArgs(TRUE)) {
  eval(parse(text = arg))

SO I can use $ Rscript myfile.R arg1 arg2 to run the script with arg1 and arg2.
Here, if argument1 is "x=1", then there is no problem. In other parts of my script file, x "equals" to 1

However, if the argument2 is "y=yes", the eval process will be halted. That makes sense. I wonder how could I make the string "yes" be assigned to y.

Any suggestion would be appreciated.
Thank you very much.

1 Like

Hi @shenliu. You may try a mix of single and double quote like this "y='yes'" or using escape "y=\"yes\"". Hope it can help.

1 Like

Perfect, thank you very much

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.