Not sure what this error is when running Google Trends queries in R

789 views Asked by At

so I'm trying to run 100 or so Google Trends queries (see code below) through R which I've done several times before with no errors

#load required package
library(gtrendsR)
library(tidyverse)
library(dplyr)

currentDate <- Sys.Date()
time <- "2010-01-01 2020-04-30"
channel <- "web"

#run queries
trends1 <- gtrends(keyword="compare", gprop=channel,geo="AU", time=time, category=249)
trends2 <- gtrends(keyword="switch", gprop=channel,geo="AU", time=time, category=249)
trends3 <- gtrends(keyword="change", gprop=channel,geo="AU", time=time, category=249)
trends4 <- gtrends(keyword="cancel", gprop=channel,geo="AU", time=time, category=249)
trends5 <- gtrends(keyword="contact", gprop=channel,geo="AU", time=time, category=249)
trends6 <- gtrends(keyword="quote", gprop=channel,geo="AU", time=time, category=249)

but now R is returning the same error after some (but not all) of the queries:

Error in `[<-.data.frame`(`*tmp*`, , timevar, value = "subject") : 
  replacement has 1 row, data has 0

If I run the query in the Google Trends website I see there is data so not sure what the error signals or why it appears on some queries and not others

1

There are 1 answers

0
Mayank Sagar On

As you mentioned, it is a case of Google Trends Package Version. The same thing happened with me and I installed the old version of gtrendsR and it worked for me , you can download the old version from the link:

gtrendsR CRAN Repository

PS: Remember to Uninstall gtrendsR before installing, you may have to restart RStudio before installing