venkata kirankumar
2009-Jun-22 06:21 UTC
[R] problem with checking wether file is present or not
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){} 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 can any one suggest any other way to make it work for all those files thanks in advance kiran [[alternative HTML version deleted]]
David Winsemius
2009-Jun-22 06:55 UTC
[R] problem with checking wether file is present or not
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 filesAnd 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 filesWithout 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
Don MacQueen
2009-Jun-22 14:23 UTC
[R] problem with checking wether file is present or not
What error is it giving? Please include the exact error. What happens if you do this: if (file.exists(findings)) cat('File',findings,'exists\n') else cat('File',findings,not found\n') Your description suggests that you are using 'if' expression inside a loop. If that is the case, try if ( !file.exists(findings) ) next inside your loop, and near the beginning of the loop. This should immediately skip to the next file, if the file is missing (and if your loop is written they way I assume it is) -Don At 11:51 AM +0530 6/22/09, 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){} > > > >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 > >can any one suggest any other way to make it work >for all those files > >thanks in advance >kiran > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list >https:// stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http:// www. R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062