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
)
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.
A character vector, listing the categories, defaults to
"0"
. Passed to gtrendsR::gtrends()
A character vector denoting geographic regions for the query,
default is "CH"
. Passed to gtrendsR::gtrends()
A string specifying the time span of the query. Possible values are:
Last hour
Last four hours
Last day
Last seven days
Past 30 days
Past 90 days
Past 12 months
Last five years (default)
Since the beginning of Google Trends (2004)
Time span between two dates (ex.: "2010-01-01 2010-04-03")
Number of attempts, in case the query request does not succeed.
Seconds to wait between attempts, where waiting time is attempt * wait
.
If TRUE won't display messages related to server interactions. Default is FALSE.
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.
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.
gtrendsR::gtrends()
, browseVignettes("intro")
x <- ts_gtrends("Rezession")
#> Downloading data for today+5-y
x
#> # A tibble: 262 × 2
#> time value
#> <date> <int>
#> 1 2020-04-26 53
#> 2 2020-05-03 56
#> 3 2020-05-10 37
#> 4 2020-05-17 38
#> 5 2020-05-24 35
#> 6 2020-05-31 33
#> 7 2020-06-07 30
#> 8 2020-06-14 25
#> 9 2020-06-21 27
#> 10 2020-06-28 18
#> # ℹ 252 more rows
tsbox::ts_plot(x)