Skip to content

Commit

Permalink
added start-end dates covid19datahub#4
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele-guidotti committed Apr 15, 2020
1 parent 2f68e77 commit bf3026c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: COVID19
Type: Package
Title: Coronavirus COVID-19 (2019-nCoV) Epidemic Datasets
Version: 0.4.1
Version: 0.4.2
Authors@R: person(given = "Emanuele", family = "Guidotti", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-8961-6623"))
Description: Unified tidy format datasets of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) epidemic across several sources. The data are downloaded in real-time, cleaned and matched with exogenous variables.
License: GPL-3
Expand Down
13 changes: 10 additions & 3 deletions R/covid19.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#'
#' @param ISO vector of ISO codes to retrieve (alpha-2, alpha-3 or numeric). Each country is identified by one of its \href{https://github.com/emanuele-guidotti/COVID19/blob/master/inst/extdata/db/ISO.csv}{ISO codes}
#' @param level integer. Granularity level. 1: country-level data. 2: state-level data. 3: city-level data.
#' @param start the start date of the period of interest.
#' @param end the end date of the period of interest. Skip yesterday by default, as some observation may be incomplete.
#' @param raw logical. Skip data cleaning? Default \code{FALSE}. See details.
#' @param cache logical. Memory caching? Significantly improves performance on successive calls. Default \code{TRUE}.
#'
Expand Down Expand Up @@ -39,7 +41,12 @@
#'
#' @export
#'
covid19 <- function(ISO = NULL, level = 1, raw = FALSE, cache = TRUE){
covid19 <- function(ISO = NULL,
level = 1,
start = "2019-01-01",
end = Sys.Date()-2,
raw = FALSE,
cache = TRUE){

# fallback
if(!(level %in% 1:3))
Expand All @@ -51,7 +58,7 @@ covid19 <- function(ISO = NULL, level = 1, raw = FALSE, cache = TRUE){
# cache
cachekey <- make.names(sprintf("covid19_%s_%s_%s",paste0(ISO, collapse = "."), level, raw))
if(cache & exists(cachekey, envir = cachedata))
return(get(cachekey, envir = cachedata))
return(get(cachekey, envir = cachedata) %>% dplyr::filter(date >= start & date <= end))

# bindings
iso_alpha_3 <- id <- date <- country <- state <- city <- confirmed <- tests <- deaths <- recovered <- hosp <- icu <- vent <- NULL
Expand Down Expand Up @@ -204,6 +211,6 @@ covid19 <- function(ISO = NULL, level = 1, raw = FALSE, cache = TRUE){
assign(cachekey, x, envir = cachedata)

# return
return(x)
return(x %>% dplyr::filter(date >= start & date <= end))

}
13 changes: 12 additions & 1 deletion man/covid19.Rd

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

0 comments on commit bf3026c

Please sign in to comment.