为什么下面的代码运行正常:
library(gtrendsR)
ch <- gconnect("usr@gmail.com", "psw")
query1 <- gtrends(query = c("Ludwig von Mises", "John Maynard Keynes", "Karl Marx"),
geo = c("BR"),
start_date = "2016-01-01",
end_date = "2016-03-31")
但如果我将日期更改为:
query2 <- gtrends(query = c("Ludwig von Mises", "John Maynard Keynes", "Karl Marx"),
geo = c("BR"),
start_date = "2010-01-01",
end_date = "2016-03-31")
R出现错误:
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
答案 0 :(得分:0)
我住在巴西。如果我这样做,包似乎没有正确处理时区:
Sys.setenv(LANG = "en", TZ = 'GMT')
在我运行代码之前,它可以工作。
如果我进入调试,则问题出在函数
上.processResults(resultsText, queryparams)
就行了
weeks <- lapply(weeks, as.POSIXct, SIMPLIFY = FALSE)
如果我改为
weeks <- lapply(weeks, as.POSIXct, SIMPLIFY = FALSE, tz = 'GMT')
它也有效。