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:

library(RCurl)

url1 = paste("ftp://user:passw...@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
server.

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,
Andrew
-- 
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.

______________________________________________
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