[R] Skip file

Duncan Murdoch murdoch.duncan at gmail.com
Wed Jul 18 15:58:00 CEST 2012

On 18/07/2012 8:27 AM, bunnylover23 at optonline.net wrote:
> What i have is a for loop to name files. I want it to skip over the file if it doesn't exist. Is there a way to do that?
> s=seq(from = chron("03/15/2012"), to = chron("06/15/2012"))
> day=format(as.Date(s), "%Y%m%d")
> for (k in 1:length(day)){
> B1=read.csv(paste("S:/file_", day[k], ".csv", sep=""))
> Date=strptime(B1[,1], format="%m/%d/%Y %I:%M:%S %p")
> print(B1) }

Use file.exists() to test for the existence of a file.

Duncan Murdoch

More information about the R-help mailing list