[R] R 2.11, shell, spaces

Duncan Murdoch murdoch.duncan at gmail.com
Wed Sep 8 00:44:21 CEST 2010


On 07/09/2010 5:01 PM, Oliver Soong wrote:
> Can somebody confirm some unexpected behavior?  This is under Windows,
> with R 2.11.0 and 2.11.1.
> 
> 1. Create a trivial test file (I called it test.R) containing:
> cat("Success.\n")
> 2. Load R (Gui or Term) and run:
> shell("\"C:\\path\\to\\Rscript.exe\" \"C:\\path\\to\\test.R\"")
> 
> In my case, I get various error messages.  If the
> path\\to\\Rscript.exe has spaces or not, it complains that the first
> token (e.g., 'C:\Program') is not a valid command.  If the
> path\\to\\Rscript.exe has no spaces, it complains that the specified
> path is invalid.  If C:\\path\\to\\test.R has no spaces, and I remove
> the surrounding quotes, things work as expected.
> 
> I think this might be related to some earlier e-mail traffic that I
> didn't see a satisfactory resolution to.

That message is coming from Windows, not from R.  R is trying to execute

cmd /c "c:\path\to\Rscript.exe" "c:\path\to\test.R"

and that doesn't work.  You'll have to ask Microsoft why, but I believe 
the correct syntax is

cmd /c "c:\path\to\Rscript.exe c:\path\to\test.R"

i.e. /c is followed by just one quoted string, not two.  If you need 
extra quotes because of spaces in the path to Rscript, I don't know what 
you can do.

I'd recommend using system() instead of shell(); it will call Rscript 
directly, not go through the cmd shell.

Duncan Murdoch

> 
> Cheers,
> Oliver
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list