get_who_cases.Rd
Downloads the latest WHO case data.It uses memoise
to cache the
results locally. To clear the cache and redownload the data use reset_cache
. The cache will be located
in the directory at which the function is run.
get_who_cases(country = NULL, daily = FALSE, cache = NULL)
country | Character string of current name |
---|---|
daily | Logical, defaults to |
cache | A |
A datatable of either all WHO data by date or cases in a specific country by date
get_who_cases#> function (country = NULL, daily = FALSE, cache = NULL) #> { #> ch <- memoise::cache_filesystem(".cache") #> mem_fread <- memoise::memoise(data.table::fread, cache = ch) #> who_cases <- mem_fread("https://raw.githubusercontent.com/eebrown/data2019nCoV/master/data-raw/WHO_SR.csv") #> who_cases$Date <- as.Date(who_cases$Date) #> if (!is.null(country)) { #> who_cases <- who_cases[, c("Date", country), with = FALSE] #> colnames(who_cases) <- c("date", "cases") #> } #> if (daily) { #> cols <- colnames(who_cases) #> cols <- cols[!colnames(who_cases) %in% c("Date", "date", #> "SituationReport")] #> safe_diff <- purrr::safely(diff) #> who_cases <- suppressWarnings(dplyr::mutate_at(who_cases, #> .vars = cols, ~as.numeric(.))) #> who_cases <- dplyr::mutate_at(who_cases, .vars = cols, #> ~. - dplyr::lag(., default = 0)) #> } #> return(who_cases) #> } #> <bytecode: 0x7ff8fd38bb98> #> <environment: namespace:NCoVUtils>