Skip to content

Commit

Permalink
support for more precise geocode (closes #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
PMassicotte committed Feb 18, 2016
1 parent cda1cae commit f62bfae
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 57 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# grtrends 1.3.2 (unreleased)

- Added support for sub-countries (#25). Ex.: `gtrends("NHL", geo = "CA-QC")` will return trends data for Québec province in Canada. The list of supported sub-countries can be obtained via `data(countries)`.

- Data parsing should work for any data returned by Google Trends (i.e. countries independent).

- Better support for queries using keywords in different languages (#50, #57). Ex.: `gtrends("蘋果", geo = "TW")`
Expand Down
9 changes: 6 additions & 3 deletions R/countries.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#' Word countries ISO code.
#'
#' \itemize{
#' \item CODE ISO 3 characters codes
#' \item COUNTRY Full countries names
#' \item code ISO 3 characters codes
#' \item country Full countries names
#' \item subcode Countries subcodes
#' \item subname Countries subname
#' }
#'
#' @docType data
#' @keywords datasets
#' @name countries
#' @usage data("countries")
#' @format A data frame with 244 rows and 2 variables
#' @format A data frame with 4707 rows and 4 variables
#' @references \url{http://www.unece.org/cefact/codesfortrade/codes_index.html}
NULL
7 changes: 3 additions & 4 deletions R/gtrends.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ gtrends.default <- function(query,

countries[, 1] <- as.character(countries[, 1])
countries[, 2] <- as.character(countries[, 2])
countries[which(countries[, "COUNTRY"] == "Namibia"), "CODE"] <- "NA"
countries[which(countries[, "country"] == "Namibia"), "code"] <- "NA"

if (geo != "" && !all(geo %in% countries[, "CODE"])) {
if (geo != "" && !all(geo %in% countries[, "code"]) && !all(geo %in% countries[, "subcode"])) {
stop("Country code not valid. Please use 'data(countries)' to retreive valid codes.",
call. = FALSE)
}
Expand Down Expand Up @@ -382,9 +382,8 @@ plot.gtrends <- function(x, type = c("trend", "geo"), which = 5, ind = 1L, ...){

# Try to find if the requested block contains geographic information.
data(locations, envir = environment())
loc <- locations

if(!any(tolower(block[1, ]) %in% tolower(loc$Name))){
if(!any(tolower(block[1, ]) %in% tolower(locations$Name))){

message("The requested block does not seems to contain geographical information. Please choose another block.")

Expand Down
19 changes: 0 additions & 19 deletions R/locations.R

This file was deleted.

2 changes: 1 addition & 1 deletion R/sport_trend.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' @examples
#' \dontrun{
#' ch <- gconnect("usr@gmail.com", "psw")
#' sport_trend <- gtrends(c("nhl", "nba", "nfl"))
#' sport_trend <- gtrends(c("nhl", "nba", "nfl"), geo = "US")
#' }
#'
#' data("sport_trend")
Expand Down
Binary file added R/sysdata.rda
Binary file not shown.
Binary file modified data/countries.RData
Binary file not shown.
Binary file removed data/locations.RData
Binary file not shown.
Binary file modified data/sport_trend.RData
Binary file not shown.
11 changes: 8 additions & 3 deletions man/countries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions man/locations.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/sport_trend.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f62bfae

Please sign in to comment.