Skip to content

Commit

Permalink
Merge pull request #273 from cmu-delphi/ds/cache-fix
Browse files Browse the repository at this point in the history
fix: improve reading of `EPIDATR_USE_CACHE` variable
  • Loading branch information
dshemetov authored Mar 8, 2024
2 parents 1ae608d + a6265f1 commit 6b98373
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: epidatr
Type: Package
Title: Client for Delphi's 'Epidata' API
Version: 1.1.3
Version: 1.1.4
Authors@R:
c(
person("Logan", "Brooks", email = "[email protected]", role = c("aut")),
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# epidatr 1.2.0

## Changes

- Improve handling of the `EPIDATR_USE_CACHE` environment variable, allowing it
to be any value convertable by `as.logical()` and handle the case when it
can't be converted.

# epidatr 1.1.1

## Changes

## Features

## Patches

- Fix failure when passing `as_of` values in `Date` format to
`pub_covidcast` while caching is enabled (#259).
- For `pub_covidcast` data source `nchs-mortality`, parse dates as `epiweek`
Expand All @@ -15,21 +24,26 @@
# epidatr 1.1.0

## Changes

- `pub_covid_hosp_state_timeseries` now supports use of the `as_of` parameter (#209).
- `release_date` and `latest_update` fields are now parsed as `Date`, rather
than as text. This change impacts several endpoints.
- `get_auth_key` renamed to `get_api_key` (#181).
- `get_api_key` no longer reads from R options and only uses environment variables (#217).
- `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.
- Updated the default `timeout_seconds` to 15 minutes to allow large queries by default.

## Features

- Function reference now displays commonly-used functions first (#205).
- Support `Date` objects passed to version arguments `as_of` and `issues` in
endpoints (#192, #194).
- `clear_cache` now handles positional arguments just like `set_cache` (#197).
- `set_api_key` now available to help persist API key environment variables (#181, #217).
- All endpoints now support the use of "\*" as a wildcard to fetch all dates or epiweeks (#234).

## Patches

- Endpoints now fail when passed misspelled arguments (#187, #201).
- `pub_fluview_meta` fixed to `fetch` the response automatically.
- `pub_covid_hosp_state_timeseries` now correctly parses the `issue` field,
Expand Down
10 changes: 8 additions & 2 deletions R/epidatr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
"_PACKAGE"

.onLoad <- function(libname, pkgname) {
cache_environ$use_cache <- Sys.getenv("EPIDATR_USE_CACHE", unset = FALSE)
cache_environ$use_cache <- (cache_environ$use_cache == "TRUE")
cache_environ$use_cache <- as.logical(Sys.getenv("EPIDATR_USE_CACHE", unset = FALSE))
if (is.na(cache_environ$use_cache)) {
cli::cli_warn(
"Failed to read EPIDATR_USE_CACHE environment variable.
Should be a logical. Defaulting to FALSE."
)
cache_environ$use_cache <- FALSE
}
if (cache_environ$use_cache) {
set_cache(startup = TRUE)
}
Expand Down

0 comments on commit 6b98373

Please sign in to comment.