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. Cheers, Oliver
On Windows, use the 8.3 name for file and directory names that have embedded blanks. You can discover the 8.3 name directly from R.> system(paste(Sys.getenv("COMSPEC"),"/c", "dir/x c:\\pr*"))Volume in drive C has no label. Volume Serial Number is B869-26CD Directory of c:\ 02/12/2010 03:52 PM <DIR> PROGRA~1 Program Files 0 File(s) 0 bytes 1 Dir(s) 84,491,341,824 bytes free>so now you know that on my machine you can say progra~1 instead of Program Files It is usually, but not always, progra~1. The 8.3 names depends on what other potentially confusing names are in the same directory. You can also do this from the DOS prompt dir /x c:\pr* Rich
Also, see R for Windows FAQ 2.16 R can't find my file, but I know it is there! On Tue, Sep 7, 2010 at 5:01 PM, Oliver Soong <osoong+r at gmail.com> wrote:> Can somebody confirm some unexpected behavior? ?This is under Windows, > with R 2.11.0 and 2.11.1.
Alternatively, you can surround the path-with-program-file-name in double quotes. "RICHARD M. HEIBERGER" <rmh at temple.edu> wrote:>On Windows, use the 8.3 name for file and directory names that have >embedded blanks. > >You can discover the 8.3 name directly from R. > >> system(paste(Sys.getenv("COMSPEC"),"/c", "dir/x c:\\pr*")) > Volume in drive C has no label. > Volume Serial Number is B869-26CD > > Directory of c:\ > >02/12/2010 03:52 PM <DIR> PROGRA~1 Program Files > 0 File(s) 0 bytes > 1 Dir(s) 84,491,341,824 bytes free >> > >so now you know that on my machine you can say > progra~1 >instead of > Program Files > > >It is usually, but not always, progra~1. The 8.3 names depends on what other >potentially confusing names are in the same directory. > >You can also do this from the DOS prompt > >dir /x c:\pr* > > >Rich > >______________________________________________ >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.--------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity.
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.
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Oliver Soong > Sent: Tuesday, September 07, 2010 2:01 PM > To: R-lists > Subject: [R] R 2.11, shell, spaces > > 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. > > Cheers, > Oliver >The shell command is a "user friendly" wrapper for the system() command, that can sometimes introduce its own difficulties (for example your quoting problems). In addition, where you may need to include double quote marks for Windows purposes, I would use single quotes for the outer quotes in the R command. Try something like the following: system('"C:\\path\\to\\Rscript.exe" "C:\\path\\to\\test.R"') This works for me on R-2.11.1 running under Windows 7 (should work for other recent versions of R and Windows XP/Vista). I also prefer to use the forward slash for paths in R since it works in windows, reduces the typing (no need to escape them), and is compatible with Unix/Linux conventions. So, the following should work as well system('"C:/path/to/Rscript.exe" "C:/path/to/test.R"') Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204