[R] Testing for the existence of a file.
joerg.maeder at ethz.ch
Fri Nov 2 08:57:44 CET 2001
try this : system('ls tmp.tmp',T)
it will return the filename (in this examplte tmp.tmp) if the file exist
or character(0) if not
to change the return value to True/False you can use the following code
as.numeric(system('ls tmp.tmp |wc -l',T))>0
Rolf Turner wrote:
> Is there any way to do this (test for the existence of a file)
> in R? In Splus (3.4) I can do
> unix(paste("test -r", fnm), output = F)
> where ``fnm'' is a character string giving the pathname of the file.
> This returns 0 if the file exists and 256 if it doesn't.
> I thought in R to do something like
> system(paste("test -r", fnm), intern =T)
> but this returns ``character(0)'' irrespective of the existence of
> the file.
> Any ideas?
> Rolf Turner
> r-help 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-help-request at stat.math.ethz.ch
Joerg Maeder IACETH INSTITUTE
PhD Student FOR ATMOSPHERIC
Phone: +41 1 633 36 25 AND CLIMATE SCIENCE
Fax: +41 1 633 10 58 ETH ZÜRICH Switzerland
r-help 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-help-request at stat.math.ethz.ch
More information about the R-help