That works
# hydeUrls = vector of urls to file names
#destList   = vector of destination file names

for(files in 1:length(hydeUrls)){
        filesFailed[files]<- FALSE
        filesFailed[files] <-
tryCatch(download.file(url=hydeUrls[files],destfile=destList[files],quiet=FALSE,mode="wb"),warning=function(m)
m<-TRUE)
 print(filesFailed[files])
 }

And below I get the result I want which has flagged this file as improperly
downloaded.
note the difference between the file length and the amount downloaded.

trying URL 'ftp://ftp.mnp.nl/hyde/hyde31_final/1870ad_pop.zip'ftp data
connection made, file length 14394402 bytesopened URLdownloaded 2.8 Mb
[1] 1



And on successful download


trying URL 'ftp://ftp.mnp.nl/hyde/hyde31_final/1910ad_pop.zip'ftp data
connection made, file length 14694703 bytesopened URLdownloaded 14.0
Mb
[1] 0



On Fri, Mar 18, 2011 at 12:17 PM, Henrique Dallazuanna <www...@gmail.com>wrote:

> 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 <mosherste...@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@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
>

        [[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