[R] Understanding tryCatch

Jonathan P Daily jdaily at usgs.gov
Fri Mar 18 20:14:38 CET 2011


tryCatch will only execute it's error function on errors. If you are 
getting warnings, you may find it helpful to set:

options(warn = 2)
?options
tryCatch(warning("!"), error = function(x) print("Error!"))
--------------------------------------
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
     - Jubal Early, Firefly

r-help-bounces at r-project.org wrote on 03/18/2011 03:04:41 PM:

> [image removed] 
> 
> [R] Understanding tryCatch
> 
> steven mosher 
> 
> to:
> 
> r-help
> 
> 03/18/2011 03:07 PM
> 
> Sent by:
> 
> r-help-bounces at r-project.org
> 
> I've read the help and the archives on tryCatch but I'm still stuggling
> trying to understand how it
> works exactly and how I can use it to get the result I need.
> 
> I have a data.frame of urls which point to 11 .zip files. Basically I 
use
> RCurl to get the list of
> files from a ftp and then reduce that directory dump to the 11 zip files 
I
> want to download.
> 
> Its easy enough to do that in a loop over the elements in data.frame.
> 
> The problem is that the site is very inconsistent. All 11 files will
> download, but I will get random
> warnings that the size of some of the files does not match what was
> downloaded.
> So at the end of the loop I may get 5 warnings about the file size not
> matching.
> These files, when tried a second or third time, will eventually download
> properly.
> 
> What I want to do is record which files had this download warning.
> 
>    [[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.



More information about the R-help mailing list