[R] Passing strings with spaces to Python using system2 splits string at whitespace

Wall, Wade A ERDC-RDE-CERL-IL Wade.A.Wall at usace.army.mil
Thu Jun 4 15:47:04 CEST 2015


Hi all,

I am trying to pass arguments to a python script using R, but am running into a problem with the string being split on the white spaces. Investigation on the python end suggests that it is happening upstream from python, because other shells such as bash have generated similar errors.

Here is example code.

R script:

test = "./Example.py"
string1 = "ThisWorks"
string2 = "This doesn't"

system2('python',args = c(as.character(test),as.character(string1))) ## This works
system2('python',args = c(as.character(test),as.character(string2))) ## This doesn't

Python script:

from sys import argv
script, string = argv
print script
print string

What happens is that string 2 is splits into "This" and "doesn't". Does anyone know how to resolve this issue? Of course I can remove the white spaces, but that may be somewhat inconvenient.

Thanks for any help.


Wade



	[[alternative HTML version deleted]]



More information about the R-help mailing list