[Rd] errors in getconnection or scan

Duncan Murdoch murdoch.duncan at gmail.com
Mon Dec 13 19:17:49 CET 2010


On 13/12/2010 12:56 PM, Arthur Charpentier wrote:
> sorry... localization is a string of characters
> for instance
> localization =
> paste("http://www.resultsfromtennis.com/",year,"/atp/",city,".html",sep="")
> where year is 2006 and city can be "wimbledon"
> hence here, since the page
> "http://www.resultsfromtennis.com/2007/atp/wimbledon.html" does exist, I
> can get the tables inside
> but
> "http://www.resultsfromtennis.com/1977/atp/shertogenbosch.html"
> does not exist... is there a way to detect that the html page does not
> exist ?

If you try to read it and get an error, you will know there's a problem. 
  For example,

x <- "http://cran.r-project.ogr"  # has a typo
con <- url(x)
html <- readLines(con)

This should produce an error, but might give you a junk page if your DNS 
provider substitutes for it.  You can catch the error using

html <- try(readLines(con), silent=TRUE)
if (inherits(html, "try-error")) cat("Error!")

Duncan Murdoch

>
>
> 2010/12/13 Duncan Murdoch <murdoch.duncan at gmail.com
> <mailto:murdoch.duncan at gmail.com>>
>
>     On 13/12/2010 12:36 PM, Arthur Charpentier wrote:
>
>         I was wondering if there was a function like "does connection
>         exists" ?
>
>
>     See ?showConnections.
>
>
>         I am currently using loops to build up a database, and I have either
>
>               B = getConnection(localization)
>
>         Error in getConnection(localization) : there is no connection
>         -2147483648
>         In addition: Warning message:
>         In getConnection(localization) : NAs introduced by coercion
>
>
>     Where did the localization variable come from?  getConnection is
>     pretty rarely used.
>
>
>
>         or
>
>               B = scan(localization)
>
>         Error in file(file, "r") : cannot open the connection
>         In addition: Warning message:
>         In file(file, "r") : cannot open: HTTP status was '404 Not Found'
>
>         is there a way to test where localization is an html page, or
>         not ? and to
>         say that if localization does exist, then scan it ?
>
>
>     What's your definition of an html page?  Testing for valid html is hard.
>
>     Duncan Murdoch
>
>



More information about the R-devel mailing list