Hello,
I am using read.table to read files directly from a public ftp site. I have
a general list of files that may or may not exist in the ftp directory, but
my hope was that R would read the file if it existed and ignored it if it
didn't exist and move on to the next one. However, when R arrives at a file
that does not exist I get the error message "Error in file(file, "rt") :
cannot open the connection" This makes sense, but I was wondering if there
was any way I could circumvent this error message and have R instead give me
a warning message without terminating my entire loop. Ideally, I would get a
warning message saying the connection does not exist, and then have R skip
to the next file.
My code is copied below.

hourly.years <- c(2000:2008)
hourly.species <- c('ch4','co2','co')
station.names <-
c('alt482n00','chm449n00','egb444n01','etl454n00','fsd449n00','llb454n01','wsa443n00','cdl453n00')
for (kk in hourly.years) {
    for (i in hourly.species) {
        for (nn in station.names) {
            file1 <- paste('ftp://gaw.kishou.go.jp/pub/data/current/
',i,'/hourly/y',kk,'/',nn,'.ec.as.cn.',i,'.nl.hr',kk,'.anc',sep='')
#ancillary data
            file2 <- paste('ftp://gaw.kishou.go.jp/pub/data/current/
',i,'/hourly/y',kk,'/',nn,'.ec.as.cn.',i,'.nl.hr',kk,'.dat',sep='')
#concentration data
            dumm.anc <- read.table(file1,skip=32,header=F,as.is=T)
            colnames(dumm.anc) <- c('DATE','TIME','WD','WS','RH','AT')
            dumm.dat <- read.table(file2,skip=32,header=F,as.is=T)
            colnames(dumm.dat) <-
c('DATE','TIME','DATE','TIME','CH4','ND','SD','F','CS','REM')
            r.obj.anc <- paste(substr(nn,1,3),i,kk,'anc.cont',sep='.')
            r.obj.dat <- paste(substr(nn,1,3),i,kk,'dat.cont',sep='.')
            assign(r.obj.anc,dumm.anc)
            assign(r.obj.dat,dumm.dat)
            status<-paste(i,nn,kk,'----EC HOURLY/CONTINUOUS DAT/ANC read
complete',sep=' ')
            print(status,quote=F)
            }
        }
    }

Thanks for any help!
Regards,
Archana

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to