Martin Maechler
1998-Dec-10 13:57 UTC
[R & Unix ..] system("test",...) gives funny results...
[in an attempt to provide system.test <- function(...) { system(paste("test", ...)) == 0 } and then file.exists <- function(file){sapply(file, function(f)system.test("-e", f))} (which would provide S-plus [>= 4.x] compatibility) ] Look at this -- ``the horror'' to me :> (system("test -e /tmp"))sh: test: argument expected [1] 256> system("type test")test is a shell builtin> system("echo $SHELL")/usr/local/bin/tcsh> (system("test -d /tmp")) # correct: it IS a directory[1] 0> (system("test -f /tmp")) # correct: it is NOT a plain file[1] 256> (system("/usr/local/bin/test -e /tmp")) ## this is GNU test from sh-utils[1] 0> (system("/usr/bin/test -e /tmp")) ##- Solaris 2.5.x[1] 0> (system("test -e /tmp"))sh: test: argument expected [1] 256 However, there doesn't seem to be a problem in the shell [/usr/local/bin/tcsh] : sophie{maechler}637> test -e /tmp; echo "$?" 0 sophie{maechler}638> test -e /tp; echo "$?" 1 ----------------- Similar funny behavior (in tcsh; $version gives the tcsh version) In the shell sophie{maechler}639> echo $version tcsh 6.04.00 (Cornell) 93/07/03 (sun4) options 8b,nls,dl,al In R : > (system("echo $version")) [1] 0 > {system("echo $version > /tmp/qq"); scan("/tmp/qq",what="")} Read 0 items character(0) > ---------- One way to get an R internal "test" -- even working in the Win/Mac version of R ?! --- would be to incorporate GNU sh-utils "test" (standalone) and provide something like test <- function(...) .Internal(test(...)) However, this probably should have to be done by someone who understands more than me about this kind of C codes. ---------- Comments, suggestions ? Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum SOL G1; Sonneggstr.33 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1086 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
1998-Dec-10 14:37 UTC
[R & Unix ..] system("test",...) gives funny results...
Martin Maechler <maechler@stat.math.ethz.ch> writes:> [in an attempt to provide > > system.test <- > function(...) { system(paste("test", ...)) == 0 } > and then > file.exists <- > function(file){sapply(file, function(f)system.test("-e", f))} > > (which would provide S-plus [>= 4.x] compatibility) > ] > > Look at this -- ``the horror'' to me : > > > (system("test -e /tmp")) > sh: test: argument expected > [1] 256Happens to me on Solaris too, but *not* on Linux!> Similar funny behavior (in tcsh; $version gives the tcsh version) > > In the shell > > sophie{maechler}639> echo $version > tcsh 6.04.00 (Cornell) 93/07/03 (sun4) options 8b,nls,dl,al > > In R : > > > (system("echo $version")) > > [1] 0 > > > {system("echo $version > /tmp/qq"); scan("/tmp/qq",what="")} > Read 0 items > character(0) > >Isn't this just because system() uses /bin/sh?> {system("echo $USER > /tmp/qq"); scan("/tmp/qq",what="")}Read 1 items [1] "pd" -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Paul Gilbert
1998-Dec-10 14:56 UTC
[R & Unix ..] system("test",...) gives funny results...
>One way to get an R internal "test" > -- even working in the Win/Mac version of R ?! ---...>However, this probably should have to be done by someone who understands >more than me about this kind of C codes.I've often wondered about this too. In my "compatibility library" I do a few similar things like copying files and checking file dates. I haven't implemented them other than in Unix and I've often thought some cross-platform issues would be resolved by doing these in C. Of course, this may just move the problem. To what extent are these kinds of things standardized across platforms in C? Paul Gilbert -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian Ripley
1998-Dec-10 16:00 UTC
[R & Unix ..] system("test",...) gives funny results...
> Date: Thu, 10 Dec 1998 14:57:58 +0100 > From: Martin Maechler <maechler@stat.math.ethz.ch>> [in an attempt to provide > > system.test <- > function(...) { system(paste("test", ...)) == 0 } > and then > file.exists <- > function(file){sapply(file, function(f)system.test("-e", f))} > > (which would provide S-plus [>= 4.x] compatibility) > ] >But surely that is not the way to do this (and how is it going to work on Windows?) S-PLUS uses a system call for file.exists, presumably to access(), even on Unix. If you want to use test, do remember that what you get is shell-specific. If you use system("/usr/bin/test -e /tmp") you have some chance of working on different shells. (Even Linux, RH5.2, has test at /usr/bin/test!) [still interested to hear about the potential of an R builtin 'test', relying on GNU sh-utils]. Why not use POSIX system calls instead? -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._