Skip to content

docs+feat+lint: final polish #168

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

Merged
merged 26 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.9.0
current_version = 1.0.0
commit = False
tag = False

Expand Down
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
linters: linters_with_defaults(
line_length_linter(120),
cyclocomp_linter = NULL
cyclocomp_linter = NULL,
object_length_linter(length = 40L)
)
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: epidatr
Type: Package
Title: Client for Delphi's Epidata API
Version: 0.9.0
Version: 1.0.0
Authors@R:
c(
person("Logan", "Brooks", email = "[email protected]", role = c("aut", "cre")),
person("Logan", "Brooks", email = "[email protected]", role = c("aut")),
person("Dmitry", "Shemetov", email = "[email protected]", role = c("aut")),
person("Samuel", "Gratzl", email = "[email protected]", role = c("aut")),
person("David", "Weber", email = "[email protected]", role = c("ctb")),
person("David", "Weber", email = "[email protected]", role = c("ctb", "cre")),
person("Alex", "Reinhart", role = c("ctb")),
person("Daniel", "McDonald", role = c("ctb")),
person("Kean Ming", "Tan", role = c("ctb")),
Expand Down Expand Up @@ -35,7 +35,6 @@ Imports:
purrr,
openssl,
readr,
rlang,
tibble,
xml2
RoxygenNote: 7.2.3
Expand All @@ -44,6 +43,7 @@ Suggests:
ggplot2,
knitr,
rmarkdown,
rlang,
testthat (>= 3.1.5),
withr
VignetteBuilder: knitr
Expand Down
43 changes: 22 additions & 21 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,40 @@
S3method(as_tibble,covidcast_data_signal_list)
S3method(as_tibble,covidcast_data_source_list)
S3method(print,covidcast_data_signal)
S3method(print,covidcast_data_signal_list)
S3method(print,covidcast_data_source)
S3method(print,covidcast_epidata)
S3method(print,epidata_call)
export("%>%")
export(avail_endpoints)
export(cache_info)
export(clear_cache)
export(covid_hosp_facility)
export(covid_hosp_facility_lookup)
export(covid_hosp_state_timeseries)
export(covidcast)
export(covidcast_epidata)
export(covidcast_meta)
export(delphi)
export(dengue_nowcast)
export(disable_cache)
export(ecdc_ili)
export(epirange)
export(fetch)
export(fetch_args_list)
export(flusurv)
export(fluview)
export(fluview_clinical)
export(fluview_meta)
export(get_auth_key)
export(gft)
export(kcdc_ili)
export(meta)
export(nidss_dengue)
export(nidss_flu)
export(nowcast)
export(paho_dengue)
export(pub_covid_hosp_facility)
export(pub_covid_hosp_facility_lookup)
export(pub_covid_hosp_state_timeseries)
export(pub_covidcast)
export(pub_covidcast_meta)
export(pub_delphi)
export(pub_dengue_nowcast)
export(pub_ecdc_ili)
export(pub_flusurv)
export(pub_fluview)
export(pub_fluview_clinical)
export(pub_fluview_meta)
export(pub_gft)
export(pub_kcdc_ili)
export(pub_meta)
export(pub_nidss_dengue)
export(pub_nidss_flu)
export(pub_nowcast)
export(pub_paho_dengue)
export(pub_wiki)
export(pvt_cdc)
export(pvt_dengue_sensors)
export(pvt_ght)
Expand All @@ -44,10 +46,8 @@ export(pvt_quidel)
export(pvt_sensors)
export(pvt_twitter)
export(set_cache)
export(wiki)
import(cachem)
import(glue)
import(openssl)
importFrom(MMWRweek,MMWRweek2Date)
importFrom(checkmate,assert)
importFrom(checkmate,assert_character)
Expand All @@ -73,6 +73,7 @@ importFrom(httr,modify_url)
importFrom(httr,stop_for_status)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(openssl,md5)
importFrom(purrr,map_chr)
importFrom(purrr,map_lgl)
importFrom(readr,read_csv)
Expand Down
20 changes: 14 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# epidatr 1.0.0

- Add `set_cache` and other caching functions.
- Prefix all non-private endpoints with `pub_`.
- Update printing of `avail_endpoints` to be more readable.
- Update printing of `covidcast_epidata()` to be more readable.
- Update landing docs to be more friendly, add plots.

# epidatr 0.9.0

- Major interface change: all endpoints now fetch by default.
Expand Down Expand Up @@ -29,13 +37,13 @@
# epidatr 0.6.0

- The `fetch_{tbl,classic,df,json,csv}` functions have been replaced by the
`fetch()` function, which almost always returns a tibble, except when used with
a limited number of older endpoints (such as `delphi()` and `meta()`), where it
will output a nested list structure.
`fetch()` function, which almost always returns a tibble, except when used with
a limited number of older endpoints (such as `delphi()` and `meta()`), where it
will output a nested list structure.

# epidatr 0.5.0

- The package that this installs is being renamed from `delphi.epidata` to
`epidatr`. To migrate, run the installation command above, followed by
`remove.packages("delphi.epidata")`, and adjust all references to the package
name accordingly.
`epidatr`. To migrate, run the installation command above, followed by
`remove.packages("delphi.epidata")`, and adjust all references to the package
name accordingly.
2 changes: 1 addition & 1 deletion R/avail_endpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ avail_endpoints <- function() {
Endpoint = paste0(h$Name, "()"),
Description = h$Title
)
tib
tib %>% print(n = 50)
}
53 changes: 22 additions & 31 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
cache_environ <- new.env(parent = emptyenv())
cache_environ$use_cache <- NULL
cache_environ$epidatr_cache <- NULL
#' create or renew a cache for this session

#' Create or renew a cache for this session
#' @aliases set_cache
#' @description
#' By default, epidatr re-requests data from the API on every call of `fetch`.
Expand Down Expand Up @@ -72,8 +73,7 @@ cache_environ$epidatr_cache <- NULL
#' dir = "some/subdir",
#' days = 14,
#' max_size = 512,
#' logfile = "some/subdir/logs.txt",
#' prune_rate = 20L
#' logfile = "some/subdir/logs.txt"
#' )
#' }
#'
Expand All @@ -90,15 +90,10 @@ cache_environ$epidatr_cache <- NULL
#' @param logfile where cachem's log of transactions is stored, relative to the
#' cache directory. By default, it is `"logfile.txt"`. The environmental
#' variable is `EPIDATR_CACHE_LOGFILE`.
#' @param prune_rate how many calls to go between checking if any cache elements
#' are too old or if the cache overall is too large. Defaults to `2000L`.
#' Since cachem fixes the max time between prune checks to 5 seconds, there's
#' little reason to actually change this parameter. Doesn't have a
#' corresponding environmental variable.
#' @param confirm whether to confirm directory creation. default is `TRUE`;
#' should only be set in non-interactive scripts
#' @seealso [clear_cache] to delete the old cache while making a new one,
#' [disable_cache] to disable without deleting, and [cache_info]
#' @seealso [`clear_cache`] to delete the old cache while making a new one,
#' [`disable_cache`] to disable without deleting, and [`cache_info`]
#' @export
#' @import cachem
#' @import glue
Expand All @@ -107,7 +102,6 @@ set_cache <- function(cache_dir = NULL,
days = NULL,
max_size = NULL,
logfile = NULL,
prune_rate = 2000L,
confirm = TRUE) {
if (is.null(cache_dir) && sessionInfo()$R.version$major >= 4) {
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR", unset = tools::R_user_dir("epidatr"))
Expand All @@ -129,7 +123,7 @@ set_cache <- function(cache_dir = NULL,
logfile <- Sys.getenv("EPIDATR_CACHE_LOGFILE", unset = "logfile.txt")
}
stopifnot(is.character(logfile))
stopifnot(is.numeric(days), is.numeric(max_size), is.integer(prune_rate))
stopifnot(is.numeric(days), is.numeric(max_size))
#
# make sure that that directory exists and drag the user into that process
cache_exists <- file.exists(cache_dir)
Expand Down Expand Up @@ -171,15 +165,14 @@ set_cache <- function(cache_dir = NULL,
dir = cache_dir,
max_size = as.integer(max_size * 1024^2),
max_age = days * 24 * 60 * 60,
logfile = file.path(cache_dir, logfile),
prune_rate = prune_rate
logfile = file.path(cache_dir, logfile)
)
}
}

#' manually reset the cache, deleting all currently saved data and starting afresh
#' Manually reset the cache, deleting all currently saved data and starting afresh
#' @description
#' deletes the current cache and resets a new cache. Deletes local data! If you
#' Deletes the current cache and resets a new cache. Deletes local data! If you
#' are using a session unique cache, you will have to pass the arguments you
#' used for `set_cache` earlier, otherwise the system-wide `.Renviron`-based
#' defaults will be used.
Expand All @@ -190,15 +183,13 @@ set_cache <- function(cache_dir = NULL,
#' days = 14,
#' max_size = 512,
#' logfile = "some/subdir/logs.txt",
#' prune_rate = 20L
#' )
#' }
#' @param disable instead of setting a new cache, disable caching entirely;
#' defaults to `FALSE`
#' @param ... see the `set_cache` arguments below
#' @inheritParams set_cache
#' @seealso [set_cache] to start a new cache (and general caching info),
#' [disable_cache] to only disable without deleting, and [cache_info]
#' defaults to `FALSE`
#' @param ... arguments passed to `set_cache`
#' @seealso [`set_cache`] to start a new cache (and general caching info),
#' [`disable_cache`] to only disable without deleting, and [`cache_info`]
#' @export
#' @import cachem
clear_cache <- function(disable = FALSE, ...) {
Expand All @@ -210,26 +201,26 @@ clear_cache <- function(disable = FALSE, ...) {
}
}

#' turn off the caching for this session
#' Turn off the caching for this session
#' @description
#' Disable caching until you call `set_cache` or restart R. The files defining
#' the cache are untouched. If you are looking to disable the caching more
#' permanently, set `EPIDATR_USE_CACHE=FALSE` as environmental variable in
#' your `.Renviron`.
#' @export
#' @seealso [set_cache] to start a new cache (and general caching info),
#' [clear_cache] to delete the cache and set a new one, and [cache_info]
#' @seealso [`set_cache`] to start a new cache (and general caching info),
#' [`clear_cache`] to delete the cache and set a new one, and [`cache_info`]
#' @import cachem
disable_cache <- function() {
cache_environ$epidatr_cache <- NULL
}

#' describe current cache
#' Describe current cache
#' @description
#' Print out the information about the cache (as would be returned by cachem's
#' `info()` method)
#' @seealso [set_cache] to start a new cache (and general caching info),
#' [clear_cache] to delete the cache and set a new one, and [disable_cache] to
#' @seealso [`set_cache`] to start a new cache (and general caching info),
#' [`clear_cache`] to delete the cache and set a new one, and [`disable_cache`] to
#' disable without deleting
#' @export
cache_info <- function() {
Expand All @@ -240,16 +231,16 @@ cache_info <- function() {
}
}

#' dispatch caching
#' Dispatch caching
#'
#' @description
#' the guts of caching, its interposed between fetch and the specific fetch
#' methods. Internal method only.
#'
#' @param call the `epidata_call` object
#' @param fetch_args the args list for fetch as generated by [fetch_args_list()]
#' @param fetch_args the args list for fetch as generated by [`fetch_args_list()`]
#' @keywords internal
#' @import cachem openssl
#' @importFrom openssl md5
cache_epidata_call <- function(epidata_call, fetch_args = fetch_args_list()) {
is_cachable <- check_is_cachable(epidata_call, fetch_args)
if (is_cachable) {
Expand Down
2 changes: 1 addition & 1 deletion R/constants.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version <- "0.9.0"
version <- "1.0.0"
http_headers <- httr::add_headers("User-Agent" = paste0("epidatr/", version), "Accept-Encoding" = "gzip")
global_base_url <- "https://api.delphi.cmu.edu/epidata/"
33 changes: 7 additions & 26 deletions R/covidcast.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parse_signal <- function(signal, base_url) {
fetch_args = fetch_args_list()) {
stopifnot(is.character(geo_type) & length(geo_type) == 1)

covidcast(
pub_covidcast(
source = signal$source,
signals = signal$signal,
geo_type = geo_type,
Expand Down Expand Up @@ -77,34 +77,15 @@ as_tibble.covidcast_data_signal_list <- function(x, ...) {
tib$format <- unname(map_chr(x, "format"))
tib$category <- unname(map_chr(x, "category"))
tib$high_values_are <- unname(map_chr(x, "high_values_are"))
if ("is_smoothed" %in% names(x)) {
tib$is_smoothed <- unname(map_lgl(x, "is_smoothed"))
} else {
tib$is_smoothed <- NA
}
if ("is_weighted" %in% names(x)) {
tib$is_weighted <- unname(map_lgl(x, "is_weighted"))
} else {
tib$is_weighted <- NA
}
if ("is_cumulative" %in% names(x)) {
tib$is_cumulative <- unname(map_lgl(x, "is_cumulative"))
} else {
tib$is_cumulative <- NA
}
if ("has_stderr" %in% names(x)) {
tib$has_stderr <- unname(map_lgl(x, "has_stderr"))
} else {
tib$has_stderr <- NA
}
if ("has_sample_size" %in% names(x)) {
tib$has_sample_size <- unname(map_lgl(x, "has_sample_size"))
} else {
tib$has_sample_size <- NA
}
as_tibble(tib)
}

#' @export
print.covidcast_data_signal_list <- function(x, ...) {
tib <- as_tibble(x)
print(tib[, c("source", "signal", "short_description")], ...)
}

#' @export
print.covidcast_data_source <- function(x, ...) {
print(x$name, ...)
Expand Down
Loading