[R] system function question

Thomas Lumley tlumley at u.washington.edu
Wed Jul 1 01:29:05 CEST 2009


On Tue, 30 Jun 2009, Erin Hodgess wrote:

> Dear R People:
>
> Does the system function return a code, (maybe zero if ok, non-zero
> otherwise), please?
>

Let's see
> a<-system("ls")
> str(a)
  int 0
> a<-system("ls foo")
ls: foo: No such file or directory
> str(a)
  int 256

Sure looks like it.  And the help page seems to agree, too:

If intern = FALSE, the return value is an error code (0 for success), given the invisible attribute (so needs to be printed explicitly). If the command could not be run for any reason, the value is 256*127 = 52512. Otherwise if wait = TRUE the value is 256 times the error code returned by the command, and if wait = FALSE it is 0 (the conventional success value).

      -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list