[R] download.file
Henrik Bengtsson
hb at biostat.ucsf.edu
Wed Nov 9 01:39:05 CET 2011
See downloadFile() of the R.utils package (on CRAN);
it allows you to download to a file to a given path (without have to
"replicate" the filename), and it also have an option (the default) to
drop zero-size files that are (sometimes) created when download.file()
tries to download a non-existing file. Moreover, the method downloads
files in binary mode by default (download in text mode is a common
cause for "corrupt" files). See help("downloadFile",
package="R.utils") for more bells and whistles.
/Henrik
On Tue, Nov 8, 2011 at 3:32 PM, Mary Kindall <mary.kindall at gmail.com> wrote:
> I am downloading say 100 files from ucsc website and storing it into dest
> folder.
> download.file function create a file in destination folder even if the file
> is not present which is something I dont want.
> So I wrote if condition to remove the file if the download function has non
> zero value.
>
> Now it exits when there is an error or file not present. How can I use
> "try" and "if" condition together so that the program does not exit on
> error and delete the created file in destination folder.
>
> for (i in 1: 100)
> {
> fileUrl = ucscfilenames[i]
> if (download.file(fileUrl, destFile, 'wget' , quiet = TRUE) != 0)
> {
> file.remove(destFile)
> }
> }
>
>
>
> thanks
>
> --
> -------------
> Mary Kindall
> Yorktown Heights, NY
> USA
>
> [[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