[R] problem with checking wether file is present or not

David Winsemius dwinsemius at comcast.net
Mon Jun 22 08:55:48 CEST 2009


On Jun 22, 2009, at 2:21 AM, venkata kirankumar wrote:

> Hi all,
> I have a problem with checking File is present in the directory or not
> like
> I have a sequence of files in one folder I have to take each file in  
> order
> and have to caliculate on those files data but in order some files are
> missing for that I have to check and load those files for that I am  
> using
>
> condition like
>
> if(file.exists(findings)==TRUE){}

What is "findings"? Have you defined it elsewhere? What was the code?  
Is findings a properly constructed file name for R's interaction with  
whatever filesystem you are using?

 >  file.exists( file="/Users/davidwinsemius/Documents/R_folder/ 
actuar.pdf")
[1] TRUE  #would have been FALSE if only the file name was used, since  
that is not my working directory.
>
>
>
> its giving results for files which are present in that folder
> but for files which are not present in that folder its giving error
> but it have to skip and run for remaining files

And am unable to reproduce the problem with a similar call.
 >  file.exists("xyz")==TRUE
[1] FALSE

You should note that file.exists returns a logical vector, so the  
comparison with TRUE is superfluous.

>
> can any one suggest any other way to make it work
> for all those files

Without more specifics it's not possible to reproduce your problem.  
Include full code and the results of sessionInfo.

?sessionInfo


>
> thanks in advance
> kiran
>
> 	[[alternative HTML version deleted]]
>
*******************
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
<!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>



David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list