Skip to content

Commit aa6c641

Browse files
authored
Merge pull request #248 from cmu-delphi/ds/cache
fix: make default cache directory R version portable
2 parents 6a9c29a + 4ef7429 commit aa6c641

File tree

15 files changed

+58
-35
lines changed

15 files changed

+58
-35
lines changed

.github/pull_request_template.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
Please:
44

5-
- [ ] Make sure this PR is against "dev", not "main".
5+
- [ ] Make sure this PR is against "dev", not "main" (unless this is a release
6+
PR).
67
- [ ] Request a review from one of the current epiprocess main reviewers:
78
brookslogan, nmdefries.
8-
- [ ] Makes sure to bump the version number in `DESCRIPTION` and `NEWS.md`.
9-
Always increment the patch version number (the third number), unless you are
10-
making a release PR from dev to main, in which case increment the minor
11-
version number (the second number).
9+
- [ ] Makes sure to bump the version number in `DESCRIPTION`. Always increment
10+
the patch version number (the third number), unless you are making a
11+
release PR from dev to main, in which case increment the minor version
12+
number (the second number).
1213
- [ ] Describe changes made in NEWS.md, making sure breaking changes
1314
(backwards-incompatible changes to the documented interface) are noted.
1415
Collect the changes under the next release number (e.g. if you are on

.github/workflows/document.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ jobs:
2626
- name: Install dependencies
2727
uses: r-lib/actions/setup-r-dependencies@v2
2828
with:
29-
extra-packages: any::roxygen2
30-
needs: roxygen2
29+
extra-packages: |
30+
any::devtools
31+
any::roxygen2
32+
needs: |
33+
devtools
34+
roxygen2
3135
3236
- name: Document
3337
run: roxygen2::roxygenise()

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: epidatr
22
Type: Package
33
Title: Client for Delphi's 'Epidata' API
4-
Version: 1.0.1
4+
Version: 1.0.2
55
Date: 2023-12-07
66
Authors@R:
77
c(
@@ -35,6 +35,7 @@ Imports:
3535
MMWRweek,
3636
purrr,
3737
openssl,
38+
rappdirs,
3839
readr,
3940
tibble,
4041
usethis,

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- `pvt_twitter` and `pub_wiki` now use `time_type` and `time_values` args instead of mutually exclusive `dates` and `epiweeks` (#236). This matches the interface of the `pub_covidcast` endpoint.
2424
- All endpoints now support the use of "\*" as a wildcard to fetch all dates or epiweeks (#234).
2525
- Fixed bug with NAs when parsing ints (#243).
26+
- Updated the default `timeout_seconds` to 15 minutes to allow large queries by default.
2627

2728
# epidatr 1.0.0
2829

R/cache.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ cache_environ$epidatr_cache <- NULL
7676
#' )
7777
#'
7878
#' @param cache_dir the directory in which the cache is stored. By default, this
79-
#' is `tools::R_user_dir()` if on R 4.0+, but must be specified for earlier
80-
#' versions of R. The path can be either relative or absolute. The
81-
#' environmental variable is `EPIDATR_CACHE_DIR`.
79+
#' is `rappdirs::user_cache_dir("R", version = "epidatr")`. The path can be
80+
#' either relative or absolute. The environmental variable is
81+
#' `EPIDATR_CACHE_DIR`.
8282
#' @param days the maximum length of time in days to keep any particular cached
8383
#' call. By default this is `1`. The environmental variable is
8484
#' `EPIDATR_CACHE_MAX_AGE_DAYS`.
@@ -103,8 +103,8 @@ set_cache <- function(cache_dir = NULL,
103103
max_size = NULL,
104104
logfile = NULL,
105105
confirm = TRUE) {
106-
if (is.null(cache_dir) && sessionInfo()$R.version$major >= 4) {
107-
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR", unset = tools::R_user_dir("epidatr"))
106+
if (is.null(cache_dir)) {
107+
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR", unset = rappdirs::user_cache_dir("R", version = "epidatr"))
108108
} else if (is.null(cache_dir)) {
109109
# earlier version, so no tools
110110
cache_dir <- Sys.getenv("EPIDATR_CACHE_DIR")
@@ -154,7 +154,6 @@ set_cache <- function(cache_dir = NULL,
154154
}
155155
}
156156

157-
158157
if (!cache_usable) {
159158
print(glue::glue(
160159
"The directory at {cache_dir} is not accessible; check permissions and/or use a different ",
@@ -168,6 +167,13 @@ set_cache <- function(cache_dir = NULL,
168167
logfile = file.path(cache_dir, logfile)
169168
)
170169
}
170+
171+
cli::cli_inform(c(
172+
"!" = "epidatr cache is being used (set env var EPIDATR_USE_CACHE=FALSE if not intended).",
173+
"i" = "The cache directory is {cache_dir}.",
174+
"i" = "The cache will be cleared after {days} days and will be pruned if it exceeds {max_size} MB.",
175+
"i" = "The log of cache transactions is stored at {file.path(cache_dir, logfile)}."
176+
))
171177
}
172178

173179
#' Manually reset the cache, deleting all currently saved data and starting afresh

R/epidatacall.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ create_epidata_call <- function(endpoint, params, meta = NULL,
8989
}
9090

9191
#' @importFrom checkmate test_class test_list
92-
request_arguments <- function(epidata_call, format_type, fields = NULL) {
92+
request_arguments <- function(epidata_call, format_type, fields) {
9393
stopifnot(inherits(epidata_call, "epidata_call"))
9494
stopifnot(format_type %in% c("json", "csv", "classic"))
9595
stopifnot(is.null(fields) || is.character(fields))
@@ -164,7 +164,7 @@ fetch_args_list <- function(
164164
disable_date_parsing = FALSE,
165165
disable_data_frame_parsing = FALSE,
166166
return_empty = FALSE,
167-
timeout_seconds = 30,
167+
timeout_seconds = 15 * 60,
168168
base_url = NULL,
169169
dry_run = FALSE,
170170
debug = FALSE,
@@ -288,7 +288,7 @@ fetch_classic <- function(epidata_call, fetch_args = fetch_args_list()) {
288288
stopifnot(inherits(epidata_call, "epidata_call"))
289289
stopifnot(inherits(fetch_args, "fetch_args"))
290290

291-
response_content <- request_impl(epidata_call, "classic", fetch_args$fields, fetch_args$timeout_seconds) %>%
291+
response_content <- request_impl(epidata_call, "classic", fetch_args$timeout_seconds, fetch_args$fields) %>%
292292
httr::content(as = "text", encoding = "UTF-8") %>%
293293
jsonlite::fromJSON(simplifyDataFrame = !fetch_args$disable_data_frame_parsing)
294294

@@ -318,7 +318,7 @@ fetch_debug <- function(epidata_call, fetch_args = fetch_args_list()) {
318318
stopifnot(inherits(epidata_call, "epidata_call"))
319319
stopifnot(inherits(fetch_args, "fetch_args"))
320320

321-
response <- request_impl(epidata_call, fetch_args$format_type, fetch_args$fields, fetch_args$timeout_seconds)
321+
response <- request_impl(epidata_call, fetch_args$format_type, fetch_args$timeout_seconds, fetch_args$fields)
322322
content <- httr::content(response, "text", encoding = "UTF-8")
323323
content
324324
}
@@ -366,7 +366,7 @@ with_base_url <- function(epidata_call, base_url) {
366366
#' @importFrom httr stop_for_status content http_type
367367
#' @importFrom xml2 read_html xml_find_all xml_text
368368
#' @keywords internal
369-
request_impl <- function(epidata_call, format_type, fields = NULL, timeout_seconds = 30) {
369+
request_impl <- function(epidata_call, format_type, timeout_seconds, fields) {
370370
stopifnot(inherits(epidata_call, "epidata_call"))
371371
stopifnot(format_type %in% c("json", "csv", "classic"))
372372

R/request.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ join_url <- function(url, endpoint) {
2222
#'
2323
#' @importFrom httr RETRY
2424
#' @keywords internal
25-
do_request <- function(url, params, timeout_seconds = 30) {
25+
do_request <- function(url, params, timeout_seconds) {
2626
# don't retry in case of certain status codes
2727
key <- get_api_key()
2828
if (key != "") {

man/clear_cache.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/do_request.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fetch_args_list.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)