Hi there. I'm trying to convert an xml derived from a url to a dataframe. It's worked (more or less) fine before, but today it seems to have broken, with error messages like:
Error in open.connection(x, "rb") :
Timeout was reached: [www.dmo.gov.uk] Connection timed out after 10000 milliseconds
And
Error in UseMethod("xml_find_all") :
no applicable method for 'xml_find_all' applied to an object of class "function"
And
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘xmlToDataFrame’ for signature ‘"function", "missing", "missing", "missing", "missing"’
In addition: Warning messages:
1: closing unused connection 4 (https://www.dmo.gov.uk/data/XmlDataReport?reportCode=D1A)
2: closing unused connection 3 (https://www.dmo.gov.uk/data/XmlDataReport?reportCode=D1A)
My code is this:
library(data.table)
library(rvest)
url <- read_html("https://www.dmo.gov.uk/data/XmlDataReport?reportCode=D1A")
dt <- rbindlist(lapply(url %>% html_nodes(css = "body > View_GILTS_IN_ISSUE > View_GILTS_IN_ISSUE") %>%
xml_attrs(),
function(x) as.data.table(t((x)))))
dt <- cbind(dt[,9, with = TRUE],
as.data.table(lapply(dt[,-9, with = TRUE], as.character)))
dt
Does anyone have any advice on where I'm going wrong?