Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not validate the geo code on our side. Closes #377. Closes #364. C… #390

Merged
merged 2 commits into from
Apr 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions R/gtrends.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,31 @@ gtrends <- function(
is.character(cookie_url)
)


## Check if valide geo
if (geo != "" &&
!all(geo %in% c(as.character(countries[, "country_code"]), as.character(countries[, "sub_code"])))) {
stop(
"Country code not valid. Please use 'data(countries)' to retreive valid codes.",
call. = FALSE
)
## Check if valid geo. There are no official source(s) that we can use to
## validate the entered geo code. However, we can use a regular expression to
## verify if the structure is valid.

m <- regexpr("^[a-zA-Z]{2}((?:-\\w{1,3}))?(?:-\\d{1,3})?", geo)
ret <- regmatches(geo, m)

if (all(geo != "")) {
if (!identical(ret, geo)) {
stop("Country code not formatted correctly.", call. = FALSE)
}
}

## Check if valide category

# if (geo != "" &&
# !all(geo %in%
# c(
# as.character(countries[, "country_code"]),
# as.character(countries[, "sub_code"])
# ))) {
# stop("Country code not valid. Please use 'data(countries)' to retrieve valid codes.",
# call. = FALSE
# )
# }

## Check if valid category
if (!all(category %in% categories[, "id"])) {
stop(
"Category code not valid. Please use 'data(categories)' to retreive valid codes.",
Expand Down