[R] download files using ftp: avoid error

Rainer Schuermann rainer.schuermann at gmx.net
Fri Sep 16 22:09:18 CEST 2011


I haven't tested it thoroughly but what worked here is replacing
> download.file(url, destfile, quiet = FALSE)
with

sys_call <- paste( "wget", url, ">", destfile, sep=" " )
system( sys_call )

Program execution continues, whether or not the download from url was 
successful. However, wget is, I believe, not available on Windows.

Rgds,
Rainer


On Friday 16 September 2011 15:07:15 Mary Kindall wrote:
> I am planning to download a large number of files from some website. I am
> using the following script.
> 
> files2down = c('aaa', 'bbb', ................)
> for (i in 1: len)
> {
> print(paste('downloading file', i, ' of total ', len));
> url = paste(urlPrefix, files2down[i], sep='')
> destfile = paste (dest, 'inDir', files2down[i], sep='/' )
> download.file(url, destfile, quiet = FALSE)
> }
> 
> It works fine as long as the file is present. When the file is not present,
> it exit from loop. Is there a way to continue looping if error occurs.
> Thanks



More information about the R-help mailing list