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]]
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.
Try this: tryCatch(log(rnorm(10)), warning = function(m)deparse(m$call[[2]])) Where log(rnorm(10)) is your expr to evaluate. On Fri, Mar 18, 2011 at 4:04 PM, steven mosher <moshersteven at gmail.com> wrote:> 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O