Unused argument in Google Trends funcion (R)

355 Views Asked by At

I am trying to retrieve a Google Trends query and I get the following error:

Error in gtrends(keyword = "hotel zypern", geo = "DE", time = "2004-01-01 2016-04-30",  : 
  unused argument (alist())

The code I have written in R:

ger1<-gtrends(
  keyword = "hotel zypern",
  geo = "DE",
  time ="2004-01-01 2016-04-30",
  gprop = c("web", "news", "images", "froogle", "youtube"),
  category = "0",
  hl = "de",
  low_search_volume = FALSE,
  cookie_url = "http://trends.google.com/Cookies/NID",
  tz = "Europe/Berlin",
  onlyInterest = "FALSE",
)

I have tried including the "..." as other posts suggested, and revised the arguments of the function but I don't find anywhere that I should include such an argument.

Thank you in advance!!

2

There are 2 best solutions below

0
On

you had an extra comma in the end. Plus: it must be: onlyInterest = FALSE (without the semicolon, it's not a string, but boolean):

ger1<-gtrends(
    keyword = "hotel zypern",
    geo = "DE",
    time ="2004-01-01 2016-04-30",
    gprop = c("web", "news", "images", "froogle", "youtube"),
    category = "0",
    hl = "de",
    low_search_volume = FALSE,
    cookie_url = "http://trends.google.com/Cookies/NID",
    tz = "Europe/Berlin",
    onlyInterest = FALSE
)

I get a warning for this, but it works. If you want to avoid this, try setting your sys.setenv:

Sys.setenv(TZ="Europe/Berlin")

Like suggested here: unknown timezone name in R strptime/as.POSIXct

0
On

You have a trailing comma at the end of the call, implying another argument. Remove that and you solve that error.

ger1<-gtrends(
  keyword = "hotel zypern",
  geo = "DE",
  time ="2004-01-01 2016-04-30",
  gprop = c("web", "news", "images", "froogle", "youtube"),
  category = "0",
  hl = "de",
  low_search_volume = FALSE,
  cookie_url = "http://trends.google.com/Cookies/NID",
  tz = "Europe/Berlin",
  onlyInterest = "FALSE"
)

You also need to watch out for the class of arguments you are passing to the function, for instance onlyInterest is looking for a boolean (FALSE), not a string ("FALSE").