Wrapper around gtrendsR::gtrends() that modifies the original function by a) vectorizing it, b) converting the result to tsboxable tibble and c) retries if no result is returned.

ts_gtrends(
  keyword = NA,
  category = "0",
  geo = "CH",
  time = "today+5-y",
  retry = 5,
  wait = 5,
  quiet = FALSE
)

Arguments

keyword

A character vector with the actual Google Trends query keywords. Defaults to NA which searches for the whole category. Contrary to gtrendsR::gtrends(), if different keywords are used, mulitple queries are sent to Google, and each series is individually normalized.

category

A character vector, listing the categories, defaults to "0". Passed to gtrendsR::gtrends()

geo

A character vector denoting geographic regions for the query, default is "CH". Passed to gtrendsR::gtrends()

time

A string specifying the time span of the query. Possible values are:

"now 1-H"

Last hour

"now 4-H"

Last four hours

"now 1-d"

Last day

"now 7-d"

Last seven days

"today 1-m"

Past 30 days

"today 3-m"

Past 90 days

"today 12-m"

Past 12 months

"today+5-y"

Last five years (default)

"all"

Since the beginning of Google Trends (2004)

"Y-m-d Y-m-d"

Time span between two dates (ex.: "2010-01-01 2010-04-03")

retry

Number of attempts, in case the query request does not succeed.

wait

Seconds to wait between attempts, where waiting time is attempt * wait.

quiet

If TRUE won't display messages related to server interactions. Default is FALSE.

Value

A tibble of time series for the different keywords or categories. If only a single keyword and a single category are specified, the tibble has columns time and value. If either more than one keyword, or more than one category are given, an additional column id indicates either the keyword, or the category.

Notes

  • The function takes the id's as strings, not the names. For example, "Arts & Entertainment" has to be specified as "2".

  • Multiple keywords or multiple categories can be specified, but not both.

Examples


x <- ts_gtrends("Rezession")
#> Downloading data for today+5-y
x
#> # A tibble: 262 × 2
#>    time       value
#>    <date>     <int>
#>  1 2019-05-12     6
#>  2 2019-05-19     0
#>  3 2019-05-26     5
#>  4 2019-06-02     0
#>  5 2019-06-09     0
#>  6 2019-06-16     6
#>  7 2019-06-23     6
#>  8 2019-06-30     7
#>  9 2019-07-07     5
#> 10 2019-07-14     0
#> # ℹ 252 more rows
tsbox::ts_plot(x)