PMassicotte / gtrendsR

R functions to perform and display Google Trends queries
353 stars 112 forks source link

Weekly data works for some weeks but not others #422

Closed tamararen closed 2 years ago

tamararen commented 2 years ago

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)

PMassicotte commented 2 years ago

Does it work on Google website?

PMassicotte commented 2 years ago

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)

tamararen commented 2 years ago

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!!!

tamararen commented 2 years ago

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

tamararen commented 2 years ago

One more thing. I just tried it for "news" and it worked. But not for "weather".

PMassicotte commented 2 years ago

Can you try the dev version?

tamararen commented 2 years ago

This one right? if (!require("devtools")) install.packages("devtools") devtools::install_github("PMassicotte/gtrendsR")

tamararen commented 2 years ago

Still not working.

tamararen commented 2 years ago

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?

PMassicotte commented 2 years ago

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?

tamararen commented 2 years ago

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)

tamararen commented 2 years ago

Thank you or your help. Looks like google trends is now working.