[R] R 2.11, shell, spaces

Oliver Soong osoong+r at gmail.com
Wed Sep 8 05:30:22 CEST 2010


Thanks, Duncan, for the pointer in the right direction.  I didn't
realize cmd's treatment of quotes was so odd.  For the curious, the
quote behavior of cmd (under XP) is here, in the Remarks under
Processing quotation marks:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true

In my case I can use system.  The only workaround I could think of for
executing a command that requires a shell (e.g., using redirection) is
to create a temporary batch file and cmd that, which is a bit ugly.

Again, thanks for all the input.
Oliver


On Tue, Sep 7, 2010 at 3:44 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> 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.
>
>



-- 
Oliver Soong
Donald Bren School of Environmental Science & Management
University of California, Santa Barbara
Santa Barbara, CA 93106-5131
805-893-7044 (office)
610-291-9706 (cell)



More information about the R-help mailing list