[R] reading non-existent files

Marc Schwartz mschwartz at medanalytics.com
Tue Jan 28 16:23:38 CET 2003


>-----Original Message-----
>From: r-help-admin at stat.math.ethz.ch 
>[mailto:r-help-admin at stat.math.ethz.ch] On Behalf Of 
>Christian.Stratowa at vie.boehringer-ingelheim.com
>Sent: Tuesday, January 28, 2003 8:59 AM
>To: r-help at stat.math.ethz.ch
>Subject: [R] reading non-existent files
>
>
>Dear R-experts
>
>I would like to read all files from a directory, the files 
>have names "myname0001.txt" etc. I paste the directory plus 
>file names and use "read.delim()". My problem is that some 
>file names are missing, so I get an error and my program 
>stops. Is there a way to check for a null pointer analogous to 
>C, so that I can simply skip non-existent filenames?
>
>Please do "Reply to all" since in the company I am not 
>subscribed to the R-help list.
>
>Thank you in advance
>Best regards
>Christian Stratowa

You could use file.exists() which returns a TRUE/FALSE to see if the
file is present or perhaps list.files() which will return a character
vector of existing files based upon a regex pattern matching string.

HTH,

Marc




More information about the R-help mailing list