我偶然发现了一个错误:
> getBDLsearch("czas")
Error in file(con, "r") : cannot open the connection
...所以我开始拆解以找出问题出在函数中的位置。这很简单,所以我将其粘贴:
require(htmltools)
getBDLsearch <- function(query = "", debug = 0, raw = FALSE) {
url <- paste0('https://api.mojepanstwo.pl/bdl/search?q=', htmlEscape(query))
if (raw) {
document <- jsonlite::fromJSON(txt = url,simplifyVector=FALSE)
return(document)
}
else {
document <- jsonlite::fromJSON(txt = url,simplifyDataFrame=TRUE)
return(document)
}
}
(https://github.com/pbiecek/SmarterPoland)
问题是当我手动运行后续行时,它就像一个魅力,变量“文档”被很好地填充。我很好奇,为什么会这样?