[R] Assistance with httr package with R version 3.3.0
David Winsemius
dwinsemius at comcast.net
Tue May 10 19:07:02 CEST 2016
> On May 10, 2016, at 10:02 AM, David Winsemius <dwinsemius at comcast.net> wrote:
>
>
>> On May 10, 2016, at 2:08 AM, boB Rudis <bob at rudis.net> wrote:
>>
>> I don't fully remember, but I doubt httr::content() ever returned a
>> character vector without using the `as="text"` parameter. Try
>> switching that line to:
>>
>> html <- content(r, as="text")
>>
Wrapping as.character around it also retrieves a version, although the first line was interpreted as a header and the the data was all character:
> str(dati)
'data.frame': 3 obs. of 6 variables:
$ 91 : chr "0,9" "" "34"
$ 90,2 : chr "16,7" "" "-96"
$ 0,8 : chr "9,018" "" "-66"
$ 0,008: chr "" "" "-128"
$ 10,2 : chr "" "" ""
$ 4,896: chr "" "" ""
>>
>>
>> On Tue, May 10, 2016 at 3:27 AM, Luca Meyer <lucam1968 at gmail.com> wrote:
>>> Hi Jim,
>>>
>>> Thank you for your suggestion. I have actually tried to upload XML and xml2
>>> but nothing changed...any other suggestion?
>>>
>>> Kind regards,
>>>
>>> Luca
>>>
>>>> rm(list=ls())
>>>> library(httr)
>>>> library(XML)
>>>> library(xml2)
>>>>
>>>> #carico i dati da Google spreadsheets
>>>> url <- "
>>> https://docs.google.com/spreadsheets/d/102-jJ7x1YfIe4Kkvb9olQ4chQ_TS90jxoU0vAbFZewc/pubhtml?gid=0&single=true
>>> "
>>>> readSpreadsheet <- function(url, sheet = 1){
>>> + r <- GET(url)
>>> + html <- content(r)
>>> + sheets <- readHTMLTable(html, header=FALSE, stringsAsFactors=FALSE)
>>> + df <- sheets[[sheet]]
>>> + dfClean <- function(df){
>>> + nms <- t(df[1,])
>>> + names(df) <- nms
>>> + df <- df[-1,-1]
>>> + row.names(df) <- seq(1,nrow(df))
>>> + df
>>> + }
>>> + dfClean(df)
>>> + }
>>>> dati <- readSpreadsheet(url)
>>> Error in (function (classes, fdef, mtable) :
>>> unable to find an inherited method for function ‘readHTMLTable’ for
>>> signature ‘"xml_document"’
>>>> rm(readSpreadsheet,url)
>>>
>>> 2016-05-10 8:52 GMT+02:00 Jim Lemon <drjimlemon at gmail.com>:
>>>
>>>> Hi Luca,
>>>> The function readHTMLtable is in the XML package, not httr. Perhaps
>>>> that is the problem as I don't see a dependency in httr for XML
>>>> (although xml2 is suggested).
>>>>
>>>> Jim
>>>>
>>>>
>>>> On Tue, May 10, 2016 at 2:58 PM, Luca Meyer <lucam1968 at gmail.com> wrote:
>>>>> Hello,
>>>>>
>>>>> I am trying to run a code I have been using for a few years now after
>>>>> downloading the new R version 3.3.0 and I get the following error:
>>>>>
>>>>>> rm(list=ls())
>>>>>> library(httr)
>>>>>>
>>>>>> #carico i dati da Google spreadsheets
>>>>>> url <- "
>>>>>
>>>> https://docs.google.com/spreadsheets/d/102-jJ7x1YfIe4Kkvb9olQ4chQ_TS90jxoU0vAbFZewc/pubhtml?gid=0&single=true
>>>>> "
>>>>>> readSpreadsheet <- function(url, sheet = 1){
>>>>> + r <- GET(url)
>>>>> + html <- content(r)
>>>>> + sheets <- readHTMLTable(html, header=FALSE, stringsAsFactors=FALSE)
>>>>> + df <- sheets[[sheet]]
>>>>> + dfClean <- function(df){
>>>>> + nms <- t(df[1,])
>>>>> + names(df) <- nms
>>>>> + df <- df[-1,-1]
>>>>> + row.names(df) <- seq(1,nrow(df))
>>>>> + df
>>>>> + }
>>>>> + dfClean(df)
>>>>> + }
>>>>>> dati <- readSpreadsheet(url)
>>>>> Error in (function (classes, fdef, mtable) :
>>>>> unable to find an inherited method for function ‘readHTMLTable’ for
>>>>> signature ‘"xml_document"’
>>>>>> rm(readSpreadsheet,url)
>>>>>
>>>>> Can anyone suggest a solution to it?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Luca
>>>>>
>>>>> [[alternative HTML version deleted]]
>>>>>
>>>>> ______________________________________________
>>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>> 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.
>>>>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
> David Winsemius
> Alameda, CA, USA
>
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list