Skip to content

Commit b5f819a

Browse files
authored
Merge pull request #168 from cmu-delphi/ds/polish
docs+feat+lint: final polish
2 parents 1e45282 + 2589d0f commit b5f819a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+402
-400
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.9.0
2+
current_version = 1.0.0
33
commit = False
44
tag = False
55

.lintr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
linters: linters_with_defaults(
22
line_length_linter(120),
3-
cyclocomp_linter = NULL
3+
cyclocomp_linter = NULL,
4+
object_length_linter(length = 40L)
45
)

DESCRIPTION

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Package: epidatr
22
Type: Package
33
Title: Client for Delphi's Epidata API
4-
Version: 0.9.0
4+
Version: 1.0.0
55
Authors@R:
66
c(
7-
person("Logan", "Brooks", email = "[email protected]", role = c("aut", "cre")),
7+
person("Logan", "Brooks", email = "[email protected]", role = c("aut")),
88
person("Dmitry", "Shemetov", email = "[email protected]", role = c("aut")),
99
person("Samuel", "Gratzl", email = "[email protected]", role = c("aut")),
10-
person("David", "Weber", email = "[email protected]", role = c("ctb")),
10+
person("David", "Weber", email = "[email protected]", role = c("ctb", "cre")),
1111
person("Alex", "Reinhart", role = c("ctb")),
1212
person("Daniel", "McDonald", role = c("ctb")),
1313
person("Kean Ming", "Tan", role = c("ctb")),
@@ -35,7 +35,6 @@ Imports:
3535
purrr,
3636
openssl,
3737
readr,
38-
rlang,
3938
tibble,
4039
xml2
4140
RoxygenNote: 7.2.3
@@ -44,6 +43,7 @@ Suggests:
4443
ggplot2,
4544
knitr,
4645
rmarkdown,
46+
rlang,
4747
testthat (>= 3.1.5),
4848
withr
4949
VignetteBuilder: knitr

NAMESPACE

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,40 @@
33
S3method(as_tibble,covidcast_data_signal_list)
44
S3method(as_tibble,covidcast_data_source_list)
55
S3method(print,covidcast_data_signal)
6+
S3method(print,covidcast_data_signal_list)
67
S3method(print,covidcast_data_source)
78
S3method(print,covidcast_epidata)
89
S3method(print,epidata_call)
910
export("%>%")
1011
export(avail_endpoints)
1112
export(cache_info)
1213
export(clear_cache)
13-
export(covid_hosp_facility)
14-
export(covid_hosp_facility_lookup)
15-
export(covid_hosp_state_timeseries)
16-
export(covidcast)
1714
export(covidcast_epidata)
18-
export(covidcast_meta)
19-
export(delphi)
20-
export(dengue_nowcast)
2115
export(disable_cache)
22-
export(ecdc_ili)
2316
export(epirange)
2417
export(fetch)
2518
export(fetch_args_list)
26-
export(flusurv)
27-
export(fluview)
28-
export(fluview_clinical)
29-
export(fluview_meta)
3019
export(get_auth_key)
31-
export(gft)
32-
export(kcdc_ili)
33-
export(meta)
34-
export(nidss_dengue)
35-
export(nidss_flu)
36-
export(nowcast)
37-
export(paho_dengue)
20+
export(pub_covid_hosp_facility)
21+
export(pub_covid_hosp_facility_lookup)
22+
export(pub_covid_hosp_state_timeseries)
23+
export(pub_covidcast)
24+
export(pub_covidcast_meta)
25+
export(pub_delphi)
26+
export(pub_dengue_nowcast)
27+
export(pub_ecdc_ili)
28+
export(pub_flusurv)
29+
export(pub_fluview)
30+
export(pub_fluview_clinical)
31+
export(pub_fluview_meta)
32+
export(pub_gft)
33+
export(pub_kcdc_ili)
34+
export(pub_meta)
35+
export(pub_nidss_dengue)
36+
export(pub_nidss_flu)
37+
export(pub_nowcast)
38+
export(pub_paho_dengue)
39+
export(pub_wiki)
3840
export(pvt_cdc)
3941
export(pvt_dengue_sensors)
4042
export(pvt_ght)
@@ -44,10 +46,8 @@ export(pvt_quidel)
4446
export(pvt_sensors)
4547
export(pvt_twitter)
4648
export(set_cache)
47-
export(wiki)
4849
import(cachem)
4950
import(glue)
50-
import(openssl)
5151
importFrom(MMWRweek,MMWRweek2Date)
5252
importFrom(checkmate,assert)
5353
importFrom(checkmate,assert_character)
@@ -73,6 +73,7 @@ importFrom(httr,modify_url)
7373
importFrom(httr,stop_for_status)
7474
importFrom(jsonlite,fromJSON)
7575
importFrom(magrittr,"%>%")
76+
importFrom(openssl,md5)
7677
importFrom(purrr,map_chr)
7778
importFrom(purrr,map_lgl)
7879
importFrom(readr,read_csv)

NEWS.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# epidatr 1.0.0
2+
3+
- Add `set_cache` and other caching functions.
4+
- Prefix all non-private endpoints with `pub_`.
5+
- Update printing of `avail_endpoints` to be more readable.
6+
- Update printing of `covidcast_epidata()` to be more readable.
7+
- Update landing docs to be more friendly, add plots.
8+
19
# epidatr 0.9.0
210

311
- Major interface change: all endpoints now fetch by default.
@@ -29,13 +37,13 @@
2937
# epidatr 0.6.0
3038

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

3644
# epidatr 0.5.0
3745

3846
- The package that this installs is being renamed from `delphi.epidata` to
39-
`epidatr`. To migrate, run the installation command above, followed by
40-
`remove.packages("delphi.epidata")`, and adjust all references to the package
41-
name accordingly.
47+
`epidatr`. To migrate, run the installation command above, followed by
48+
`remove.packages("delphi.epidata")`, and adjust all references to the package
49+
name accordingly.

R/avail_endpoints.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ avail_endpoints <- function() {
1717
Endpoint = paste0(h$Name, "()"),
1818
Description = h$Title
1919
)
20-
tib
20+
tib %>% print(n = 50)
2121
}

R/cache.R

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
cache_environ <- new.env(parent = emptyenv())
44
cache_environ$use_cache <- NULL
55
cache_environ$epidatr_cache <- NULL
6-
#' create or renew a cache for this session
6+
7+
#' Create or renew a cache for this session
78
#' @aliases set_cache
89
#' @description
910
#' By default, epidatr re-requests data from the API on every call of `fetch`.
@@ -72,8 +73,7 @@ cache_environ$epidatr_cache <- NULL
7273
#' dir = "some/subdir",
7374
#' days = 14,
7475
#' max_size = 512,
75-
#' logfile = "some/subdir/logs.txt",
76-
#' prune_rate = 20L
76+
#' logfile = "some/subdir/logs.txt"
7777
#' )
7878
#' }
7979
#'
@@ -90,15 +90,10 @@ cache_environ$epidatr_cache <- NULL
9090
#' @param logfile where cachem's log of transactions is stored, relative to the
9191
#' cache directory. By default, it is `"logfile.txt"`. The environmental
9292
#' variable is `EPIDATR_CACHE_LOGFILE`.
93-
#' @param prune_rate how many calls to go between checking if any cache elements
94-
#' are too old or if the cache overall is too large. Defaults to `2000L`.
95-
#' Since cachem fixes the max time between prune checks to 5 seconds, there's
96-
#' little reason to actually change this parameter. Doesn't have a
97-
#' corresponding environmental variable.
9893
#' @param confirm whether to confirm directory creation. default is `TRUE`;
9994
#' should only be set in non-interactive scripts
100-
#' @seealso [clear_cache] to delete the old cache while making a new one,
101-
#' [disable_cache] to disable without deleting, and [cache_info]
95+
#' @seealso [`clear_cache`] to delete the old cache while making a new one,
96+
#' [`disable_cache`] to disable without deleting, and [`cache_info`]
10297
#' @export
10398
#' @import cachem
10499
#' @import glue
@@ -107,7 +102,6 @@ set_cache <- function(cache_dir = NULL,
107102
days = NULL,
108103
max_size = NULL,
109104
logfile = NULL,
110-
prune_rate = 2000L,
111105
confirm = TRUE) {
112106
if (is.null(cache_dir) && sessionInfo()$R.version$major >= 4) {
113107
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR", unset = tools::R_user_dir("epidatr"))
@@ -129,7 +123,7 @@ set_cache <- function(cache_dir = NULL,
129123
logfile <- Sys.getenv("EPIDATR_CACHE_LOGFILE", unset = "logfile.txt")
130124
}
131125
stopifnot(is.character(logfile))
132-
stopifnot(is.numeric(days), is.numeric(max_size), is.integer(prune_rate))
126+
stopifnot(is.numeric(days), is.numeric(max_size))
133127
#
134128
# make sure that that directory exists and drag the user into that process
135129
cache_exists <- file.exists(cache_dir)
@@ -171,15 +165,14 @@ set_cache <- function(cache_dir = NULL,
171165
dir = cache_dir,
172166
max_size = as.integer(max_size * 1024^2),
173167
max_age = days * 24 * 60 * 60,
174-
logfile = file.path(cache_dir, logfile),
175-
prune_rate = prune_rate
168+
logfile = file.path(cache_dir, logfile)
176169
)
177170
}
178171
}
179172

180-
#' manually reset the cache, deleting all currently saved data and starting afresh
173+
#' Manually reset the cache, deleting all currently saved data and starting afresh
181174
#' @description
182-
#' deletes the current cache and resets a new cache. Deletes local data! If you
175+
#' Deletes the current cache and resets a new cache. Deletes local data! If you
183176
#' are using a session unique cache, you will have to pass the arguments you
184177
#' used for `set_cache` earlier, otherwise the system-wide `.Renviron`-based
185178
#' defaults will be used.
@@ -190,15 +183,13 @@ set_cache <- function(cache_dir = NULL,
190183
#' days = 14,
191184
#' max_size = 512,
192185
#' logfile = "some/subdir/logs.txt",
193-
#' prune_rate = 20L
194186
#' )
195187
#' }
196188
#' @param disable instead of setting a new cache, disable caching entirely;
197-
#' defaults to `FALSE`
198-
#' @param ... see the `set_cache` arguments below
199-
#' @inheritParams set_cache
200-
#' @seealso [set_cache] to start a new cache (and general caching info),
201-
#' [disable_cache] to only disable without deleting, and [cache_info]
189+
#' defaults to `FALSE`
190+
#' @param ... arguments passed to `set_cache`
191+
#' @seealso [`set_cache`] to start a new cache (and general caching info),
192+
#' [`disable_cache`] to only disable without deleting, and [`cache_info`]
202193
#' @export
203194
#' @import cachem
204195
clear_cache <- function(disable = FALSE, ...) {
@@ -210,26 +201,26 @@ clear_cache <- function(disable = FALSE, ...) {
210201
}
211202
}
212203

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

227-
#' describe current cache
218+
#' Describe current cache
228219
#' @description
229220
#' Print out the information about the cache (as would be returned by cachem's
230221
#' `info()` method)
231-
#' @seealso [set_cache] to start a new cache (and general caching info),
232-
#' [clear_cache] to delete the cache and set a new one, and [disable_cache] to
222+
#' @seealso [`set_cache`] to start a new cache (and general caching info),
223+
#' [`clear_cache`] to delete the cache and set a new one, and [`disable_cache`] to
233224
#' disable without deleting
234225
#' @export
235226
cache_info <- function() {
@@ -240,16 +231,16 @@ cache_info <- function() {
240231
}
241232
}
242233

243-
#' dispatch caching
234+
#' Dispatch caching
244235
#'
245236
#' @description
246237
#' the guts of caching, its interposed between fetch and the specific fetch
247238
#' methods. Internal method only.
248239
#'
249240
#' @param call the `epidata_call` object
250-
#' @param fetch_args the args list for fetch as generated by [fetch_args_list()]
241+
#' @param fetch_args the args list for fetch as generated by [`fetch_args_list()`]
251242
#' @keywords internal
252-
#' @import cachem openssl
243+
#' @importFrom openssl md5
253244
cache_epidata_call <- function(epidata_call, fetch_args = fetch_args_list()) {
254245
is_cachable <- check_is_cachable(epidata_call, fetch_args)
255246
if (is_cachable) {

R/constants.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version <- "0.9.0"
1+
version <- "1.0.0"
22
http_headers <- httr::add_headers("User-Agent" = paste0("epidatr/", version), "Accept-Encoding" = "gzip")
33
global_base_url <- "https://api.delphi.cmu.edu/epidata/"

R/covidcast.R

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ parse_signal <- function(signal, base_url) {
2424
fetch_args = fetch_args_list()) {
2525
stopifnot(is.character(geo_type) & length(geo_type) == 1)
2626

27-
covidcast(
27+
pub_covidcast(
2828
source = signal$source,
2929
signals = signal$signal,
3030
geo_type = geo_type,
@@ -77,34 +77,15 @@ as_tibble.covidcast_data_signal_list <- function(x, ...) {
7777
tib$format <- unname(map_chr(x, "format"))
7878
tib$category <- unname(map_chr(x, "category"))
7979
tib$high_values_are <- unname(map_chr(x, "high_values_are"))
80-
if ("is_smoothed" %in% names(x)) {
81-
tib$is_smoothed <- unname(map_lgl(x, "is_smoothed"))
82-
} else {
83-
tib$is_smoothed <- NA
84-
}
85-
if ("is_weighted" %in% names(x)) {
86-
tib$is_weighted <- unname(map_lgl(x, "is_weighted"))
87-
} else {
88-
tib$is_weighted <- NA
89-
}
90-
if ("is_cumulative" %in% names(x)) {
91-
tib$is_cumulative <- unname(map_lgl(x, "is_cumulative"))
92-
} else {
93-
tib$is_cumulative <- NA
94-
}
95-
if ("has_stderr" %in% names(x)) {
96-
tib$has_stderr <- unname(map_lgl(x, "has_stderr"))
97-
} else {
98-
tib$has_stderr <- NA
99-
}
100-
if ("has_sample_size" %in% names(x)) {
101-
tib$has_sample_size <- unname(map_lgl(x, "has_sample_size"))
102-
} else {
103-
tib$has_sample_size <- NA
104-
}
10580
as_tibble(tib)
10681
}
10782

83+
#' @export
84+
print.covidcast_data_signal_list <- function(x, ...) {
85+
tib <- as_tibble(x)
86+
print(tib[, c("source", "signal", "short_description")], ...)
87+
}
88+
10889
#' @export
10990
print.covidcast_data_source <- function(x, ...) {
11091
print(x$name, ...)

0 commit comments

Comments
 (0)