[R] how to get xmlToList() to retry if http fails

Waichler, Scott R Scott.Waichler at pnnl.gov
Wed Mar 6 22:12:58 CET 2013


Hi,

I am using xmlToList() in a loop with a call to a webservice, per the code below.  

  # Loop thru target locs
  for(i in 1:num.target.locs) {
    url <- paste(sep="/", "http://www.earthtools.org/timezone", lat[i], lon[i])
    tmp <- xmlToList(url)
    df$time.offset[i] <- tmp$offset
    system("sleep 1")  # wait 1 second per requirements of above web service
  }  # end loop thru target locations

Failure struck midway through my loop, with the message below.

failed to load HTTP resource
Error: 1: failed to load HTTP resource

I presume that the webservice failed to respond in this instance.  How can I trap the error and have it retry after waiting a second or two, instead of exiting?

Thanks.  --Scott Waichler
Pacific Northwest National Laboratory
Richland, WA, USA
scott.waichler at pnnl.gov



More information about the R-help mailing list