[R] Problem with using read.csv with web address

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Aug 13 00:19:34 CEST 2008


2008/8/12 Aiste Aistike <aiste.aistike at gmail.com>:
> Hello,
>
> I have a problem with using read.csv(). I want to read a table from the ONS
> neighborhood statistics website which has an address:
>
> http://www.neighbourhood.statistics.gov.uk/dissemination/LeadTableView.do?a=3&b=5940246&c=Stoke&d=14&e=7&f=73&g=401878&i=1001x1003x1004x1005&l=145&o=1&m=0&r=1&s=1211997884568&enc=1&downloadTable=Download+this+table
>
> I was trying the following:
>
> #the parameter FamilyId I will need to change to get other datasets
> url1 <-  paste("
> http://www.neighbourhood.statistics.gov.uk/dissemination/LeadTableView.do?a=3&b=5940246&c=Stoke&d=14&e=7&f=73&g=401878&i=1001x1003x1004x1005&l=",FamilyId,"&o=1&m=0&r=1&s=1211997884568&enc=1&downloadTable=Download+this+table",
> sep="")
> x <- read.csv(url1, header = FALSE, stringsAsFactors = FALSE)

 It looks like that URL doesn't actually return the CSV. The page you
get back has a 'refresh' meta-tag in it which sends your web browser
(firefox/IE) to another location. R doesn't care about this - because
it makes no attempt to make sense of the returned page - it just
returns what it got with the web request.

 There's also bits of JavaScript and other cruft in there. I can't
find a direct URL that gets the CSV straightaway which is what you
need. There's session id's and so on in the URL which might be
confusing things. I'll keep nosing around because this is a wonderful
example of how *not* to do web design.

What a mess!

Barry



More information about the R-help mailing list