Skip to content

Commit

Permalink
force [ for other country to query province-level data
Browse files Browse the repository at this point in the history
  • Loading branch information
GuangchuangYu committed Mar 20, 2020
1 parent a6ca75b commit fe7ad34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions R/main-country.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
country_list <- c("China","South Korea","United States","Japan","Iran",
"Italy","Germany","United Kingdom")

nCov2019_set_country <- function(country = "China") {
country_list <- c("China","South Korea","United States","Japan","Iran",
"Italy","Germany","United Kingdom")
if (!country %in% country_list) {
msg <- paste("only the following supported countries have detail information:\n",
paste(country_list, collapse=","), "\n",
Expand Down
14 changes: 9 additions & 5 deletions R/subset.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##' @method [ nCov2019History
##' @export
`[.nCov2019History` <- function(object, i, j, ...) {
`[.nCov2019History` <- function(object, i, j, quiet = TRUE, ...) {
obj <- object$data
# get the country setting
country_option = getOption("nCov2019.country")
Expand All @@ -18,10 +18,14 @@
obj = subset(obj[, j, drop=FALSE],country == country_option)
return(obj)
} else {
msg <- paste("Only China have city level information now\n",
"Please use x['province'] to access information at province level\n",
"Or use x['global'] to access information at country level\n")
stop(msg)
if (!quiet) {
msg <- paste("Only China have city-level information.\n",
paste0("Province-level information are available for specific countries \n\t(",
paste0(country_list[country_list != "China"], collapse=","),")\n"),
"You can also use x['global'] to access information at country-level\n")
message(msg)
}
i <- "province"
}
}
# return province data base on the country_option
Expand Down

0 comments on commit fe7ad34

Please sign in to comment.