Re: [R] download.file error

From: jim holtman <jholtman_at_gmail.com>
Date: Tue, 01 Apr 2008 10:25:32 -0500

?file.exists

On 4/1/08, CHIB CO <chibco_at_hotmail.com> wrote:
> Hi Jim,
>
> I just wanted to know if there is a function in R that can tell you whether
> a file on the internet exists before you attempt to download it or whether
> there is a way of handling the error you get in the download.file() function
> without having it break a for loop with the download error when it is part
> of that loop.
>
> Kind Regards
>
> Chib
>
>
> ________________________________
>
> > Date: Mon, 31 Mar 2008 18:33:35 -0500
> > From: jholtman_at_gmail.com
> > To: chibco_at_hotmail.com
> > Subject: Re: [R] download.file error
> > CC: r-help_at_r-project.org
>
> >
> > ?try
> >
> > On Mon, Mar 31, 2008 at 6:26 PM, CHIB CO <chibco_at_hotmail.com> wrote:
> > > Dear all,
> > >
> > > I am looking for a way to work out if a file on the internet exists
> before attempting to download it using the function download.file(). For
> example,
> > > using a url that does not exist
> > >
> > > url <- "http://finance.yahoo.com/ftse.csv"
> > > destfile <- tempfile()
> > > download.file(url = url, destfile = destfile)
> > >
> > > # gives the following response ...
> > >
> > > trying URL 'http://finance.yahoo.com/ftse.csv'
> > > Error in download.file(url = url, destfile = destfile) :
> > > cannot open URL 'http://finance.yahoo.com/ftse.csv'
> > > In addition: Warning message:
> > > In download.file(url = url, destfile = destfile) :
> > > cannot open: HTTP status was '404 Not Found'
> > >
> > > When I am using the download.file() function in a loop over multiple
> URLs, the above error will cause the loop to terminate, so I want to avoid
> this by checking if the file exists first then wrapping the subsequent
> functions in an if() statment. The original fault came from the function
> get.hist.quote() in the "tseries" package. I was trying to iterate over
> various stocks, but some stocks listed in the yahoo website do not have any
> downloadable data associated with them, which causes the loop to terminate.
> The "workhorse" function of get.hist.quote() is the download.file()
> function.
> > >
> > > Kind Regards
> > >
> > > Chib
> > >
> > >
> _________________________________________________________________
> > > Win 100's of Virgin Experience days with BigSnapSearch.com
> > >
> > > [[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.
> > >
> > >
> >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem you are trying to solve?
>
>
> ________________________________
> Have you played Fishticuffs? Get fish-slapping on Messenger

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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.
Received on Tue 01 Apr 2008 - 16:06:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Apr 2008 - 16:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive