[R] Command that is conditional upon file retrieval: is it possible?

AndrewPage savejarvis at yahoo.com
Wed Jul 21 23:33:07 CEST 2010

Hi all,

I'm currently working on an R program where I have to access an FTP server
to download some of the data I need.  However, the people who post up the
files I access are at times inconsistent with regards to time posted, if
they post at all, etc....  Here's some of the code I use:


url1 = paste("ftp://user:password@a.great.website.com/", "file", num1,
".csv", sep = "")

data1 = getURL(url1)

write(data1, file = paste("inMyFolder", num1, ".csv", sep = ""))

Sometimes this process works perfectly, and sometimes I get an error message
like this attached to "data1 = getURL(url1)":

Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) : 
  RETR response: 550

That's because that particular file isn't on the FTP server yet.  Now...
let's just imagine that there's another way for me to access the file
elsewhere, and I can drag it into the working directory with the same name
as the file I'm telling R to write immediately after finding it on the FTP

So here's my question: is it possible to write a command that will write the
file if there isn't an error message going along with "data1 =
getURL(url1)", but won't write the file if it can't find it????  As of right
now, if I got the error message, dragged the file into the working directory
and ran the program again, R will overwrite my good file with an empty one
because in all cases, I'm telling it to write a file with that name that
includes the information in "data1".

Thanks in advance,
View this message in context: http://r.789695.n4.nabble.com/Command-that-is-conditional-upon-file-retrieval-is-it-possible-tp2297811p2297811.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list