[R] Problem Invoking System Commands from R

Matt Borkowski mathias1979 at yahoo.com
Sat Oct 11 15:05:30 CEST 2014


I appreciate the feedback.

1) The paths are properly set...I only wonder if the spaces in the path to wget.exe are problematic for R. The full path (C:\\Program Files (x86)\\GnuWin32\\bin) is properly included in the return list for Sys.getenv("PATH"). Sys.which("wget") returns:

>"C:\\PROGRA~2\\GnuWin32\\bin\\wget.exe"

Note that in this return, the folder 'Program Files (x86)' was truncated. Not sure if that is a problem in this. Also as mentioned, wget works fine directly from the Windows CMD line, so it strikes me as an issue calling a system command from R as opposed to a problem with the command itself.

2) 'dir' is a recognized command at the Windows command line...but it is somewhat irrelevant as I was only using it to determine whether any calls to the Windows command line from R were working...it is not essential to the script.

One further point, I booted up my old machine last night and reinstalled R and wget...and was successfully able to run the script. Old machine is Windows XP versus Windows 8.1 on my new machine. Perhaps this confirms it is a Windows permission issue and not an R problem?

-Matt


On Saturday, October 11, 2014 3:00 AM, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:



Please do follow the posting guide and not sent HTML: it gets mangled.

There are two issues here:

1) Paths.  Use Sys.which("wget") to see if the command is on your path. 
  I suspect it is not, and you need to set the path when running R in 
the same way as is done for your shell.  Compare the setting of PATH in 
your shell with Sys.getenv("PATH") in R, and use Sys.getenv() to set it 
(or do so on the shortcut used to start R: see the rw-FAQ).

3) AFAIR 'dir' is not a system command.  See ?system (on Windows) and 
note that shell() is required for some commands: this is one.

These are not R issues, and you may need to seek local Windows help.


On 11/10/2014 02:20, Matt Borkowski wrote:
> Hello,
> First please keep in mind I am not a programmer and know very little about R. I am running the 64bit version of R on a Windows 8.1 machine. I am trying to run a script (which I have successfully run in the past) to download some weather data from a NOAA ftp site.
> When I attempt to run the following command:     system("wget -P data/raw ftp://ftp.ncdc.noaa.gov/pub/data/noaa/2013/724620-23061-2013.gz")
>
> it returns status 127, which as I understand simply means the command will not run.
> If I go directly to my command prompt in Windows, navigate to my working director, and run     wget -P data/raw ftp://ftp.ncdc.noaa.gov/pub/data/noaa/2013/724620-23061-2013.gz
> the command runs and the file downloads without a problem.
> Playing around, it seems I can't invoke any system commands from R. Even a simple      system("dir")
> returns status 127.
> I have moved to a new computer since I last successfully ran this script...I'm wondering if this might be a permissions issue or other security setting preventing me from invoking system commands.
> Any ideas?
> -Matt
>     [[alternative HTML version deleted]]


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK



More information about the R-help mailing list