Weekly data works for some weeks but not others
tamararen opened this issue · 12 comments
Hi,
I'm requesting weekly data from gtrendsR for Great Britain over 2021. I'm pulling each week at a time, so the input for time looks like "2021-01-03 2021-01-09" for the first request and "2021-01-10 2021-01-16" for the next request and so forth. This issue I'm running into is that when I request data for "2021-01-03 2021-01-09" it works. When I request data for "2021-01-17 2021-01-23" it works. But when I request data for "2021-01-10 2021-01-16" it gives me the following error:
Error in start_top:end_top : NA/NaN argument
The code I'm using is the following function, in which I change the time input for the various queries. Is there a reason why I'm getting this error code? Thank you.
gtrends(keyword = "Weather",
geo = "GB",
time = "2021-01-10 2021-01-16",
gprop = "web",
category = 0,
low_search_volume = TRUE, #FALSE is the same
compared_breakdown = FALSE)
Does it work on Google website?
Are you using the latest version? Looks like it is working on my side:
library(gtrendsR)
plot(gtrends(
keyword = "Weather",
geo = "GB",
time = "2021-01-10 2021-01-16",
gprop = "web",
category = 0,
low_search_volume = TRUE,
#FALSE is the same
compared_breakdown = FALSE
))
Created on 2022-06-16 by the reprex package (v2.0.1)
It definitely works on the website. Hmm I just uploaded the packages. I have version 1.5.1. If it's the same I'm going to see if it's my R version. Thank you for your quick response!!!
I reinstalled and updated all the packages and R. It's still giving me the error. Not sure why still, but I'll keep working on it. Thank you for your help.
Tami
One more thing. I just tried it for "news" and it worked. But not for "weather".
Can you try the dev version?
This one right? if (!require("devtools")) install.packages("devtools")
devtools::install_github("PMassicotte/gtrendsR")
Still not working.
So out of curiosity, I tried "Weather" and "Er" and "Weath+er" and it works, but not "Weather". I was running a forloop/lapply function to pull weekly data for Weather so maybe it flagged the word?
Humm cannot really tell at the moment. I just tried on another computer, and it also works.
What do you mean when you say:
so maybe it flagged the word?
Flagged in it's stopping the function from working? I don't know. I just tried the for loop function with "News". It broke after the third week. I plugged that week into gtrends() and it's giving me the same error as in the case of "Weather". It's almost like R stores in memory that that particular week doesn't work for some reason.
Here's the error when the for loop breaks:
function (object, open = "r", local = FALSE, name = deparse1(substitute(object)),
encoding = c("", "bytes", "UTF-8"))
{
env <- if (local)
parent.frame()
else .GlobalEnv
type <- match(match.arg(encoding), c("", "bytes", "UTF-8"))
if (!(is.character(name) && length(name) == 1))
stop("'name' must be a single character string")
.Internal(textConnection(name, object, open, env, type))
}
I then run the gtrends function with the week that the for loop broke and get the same Na/NaN error. Here's the code I used:
gtrends(
keyword = "News",
geo = "GB",
time = "2021-01-24 2021-01-30",
gprop = "web",
category = 0,
low_search_volume = TRUE,
compared_breakdown = FALSE)
Thank you or your help. Looks like google trends is now working.