Skip to content

Commit

Permalink
Merge pull request #156 from cmu-delphi/ds/merge-fetch
Browse files Browse the repository at this point in the history
refactor: `fetch` by default
  • Loading branch information
dshemetov authored Aug 30, 2023
2 parents 3db0081 + a25e532 commit 7f2d73a
Show file tree
Hide file tree
Showing 61 changed files with 1,118 additions and 516 deletions.
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.8.0
current_version = 0.9.0
commit = False
tag = False

Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @dshemetov @brookslogan
* @dshemetov @brookslogan @dsweber2
12 changes: 1 addition & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,7 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::devtools, any::rcmdcheck, any::styler, any::lintr, local::.

- name: Style / Format
shell: Rscript {0}
run: styler::style_pkg(dry="fail")

- name: Lint
shell: Rscript {0}
run: |
devtools::load_all()
lintr::lint_package('.')
extra-packages: any::devtools, any::rcmdcheck, local::.

- uses: r-lib/actions/check-r-package@v2
env:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/document.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
paths: ["R/**"]

name: Document

jobs:
document:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::roxygen2
needs: roxygen2

- name: Document
run: roxygen2::roxygenise()
shell: Rscript {0}

- name: Commit and push changes
run: |
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git add man/\* NAMESPACE DESCRIPTION
git commit -m "docs: update documentation (GHA)" || echo "No changes to commit"
git pull --ff-only
git push origin
32 changes: 32 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master, dev]
pull_request:
branches: [main, master, dev]

name: lint

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.
needs: lint

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
73 changes: 73 additions & 0 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
paths: ["**.[rR]", "**.[qrR]md", "**.[rR]markdown", "**.[rR]nw", "**.[rR]profile"]

name: Style

jobs:
style:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Install dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::styler, any::roxygen2
needs: styler

- name: Enable styler cache
run: styler::cache_activate()
shell: Rscript {0}

- name: Determine cache location
id: styler-location
run: |
cat(
"location=",
styler::cache_info(format = "tabular")$location,
"\n",
file = Sys.getenv("GITHUB_OUTPUT"),
append = TRUE,
sep = ""
)
shell: Rscript {0}

- name: Cache styler
uses: actions/cache@v3
with:
path: ${{ steps.styler-location.outputs.location }}
key: ${{ runner.os }}-styler-${{ github.sha }}
restore-keys: |
${{ runner.os }}-styler-
${{ runner.os }}-
- name: Style
run: styler::style_pkg()
shell: Rscript {0}

- name: Commit and push changes
run: |
if FILES_TO_COMMIT=($(git diff-index --name-only ${{ github.sha }} \
| egrep --ignore-case '\.(R|[qR]md|Rmarkdown|Rnw|Rprofile)$'))
then
git config --local user.name "$GITHUB_ACTOR"
git config --local user.email "[email protected]"
git commit ${FILES_TO_COMMIT[*]} -m "style: styler (GHA)"
git pull --ff-only
git push origin
else
echo "No changes to commit."
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ env
/doc/
/Meta/
.secrets
epidatr.Rproj
2 changes: 1 addition & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
linters: with_defaults(
linters: linters_with_defaults(
line_length_linter(120),
cyclocomp_linter = NULL
)
3 changes: 1 addition & 2 deletions 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: 0.8.0
Version: 0.9.0
Authors@R:
c(
person("Logan", "Brooks", email = "[email protected]", role = c("aut", "cre")),
Expand All @@ -25,7 +25,6 @@ Imports:
magrittr,
MMWRweek,
readr,
rlang,
tibble,
xml2
RoxygenNote: 7.2.3
Expand Down
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(dengue_nowcast)
export(ecdc_ili)
export(epirange)
export(fetch)
export(fetch_args_list)
export(flusurv)
export(fluview)
export(fluview_clinical)
Expand All @@ -38,11 +39,12 @@ export(pvt_quidel)
export(pvt_sensors)
export(pvt_twitter)
export(wiki)
export(with_base_url)
importFrom(MMWRweek,MMWRweek2Date)
importFrom(checkmate,assert)
importFrom(checkmate,assert_character)
importFrom(checkmate,assert_integerish)
importFrom(checkmate,assert_logical)
importFrom(checkmate,assert_numeric)
importFrom(checkmate,check_character)
importFrom(checkmate,check_class)
importFrom(checkmate,check_date)
Expand All @@ -63,7 +65,6 @@ importFrom(httr,stop_for_status)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(readr,read_csv)
importFrom(rlang,abort)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(xml2,read_html)
Expand Down
19 changes: 13 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# epidatr 0.9.0

- Major interface change: all endpoints now fetch by default.
- Make all `fetch` function internal.
- Change `fetch` and `fetch_*` function interfaces now rely on `fetch_args_list`.
- Added `fetch_args_list` which returns a list of arguments to be passed to `fetch`.

# epidatr 0.8.0

- Fix source name duplication bug in `covidcast_epidata`
- Mark `covidcast_epidata` as experimental and do not export it
- Change `covidcast` arg `data_source` to `source`
- Make `covidcast` args `issues`, `lag`, and `as_of` mutually exclusive
- Fix source name duplication bug in `covidcast_epidata`.
- Mark `covidcast_epidata` as experimental and do not export it.
- Change `covidcast` arg `data_source` to `source`.
- Make `covidcast` args `issues`, `lag`, and `as_of` mutually exclusive.
- Make `covid_hosp_facility_lookup` args `state,` `ccn`, `city`, `zip`, and
`fips_code` mutually exclusive
`fips_code` mutually exclusive.
- Update documentation to only refer to character or strings (not character
vectors or character strings)
vectors or character strings).

# epidatr 0.7.1

Expand Down
8 changes: 4 additions & 4 deletions R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ get_auth_key <- function() {
return(key)
}

rlang::warn(
cli::cli_warn(
c(
"No API key found. You will be limited to non-complex queries and encounter rate limits if you proceed.",
"To avoid this, you can get your key by registering at https://api.delphi.cmu.edu/epidata/admin/registration_form and then:",
"No API key found. You will be limited to non-complex queries and encounter rate limits if you proceed.
To avoid this, you can get your key by registering
at https://api.delphi.cmu.edu/epidata/admin/registration_form and then:",
"i" = "set the environment variable DELPHI_EPIDATA_KEY",
"i" = "set the option 'delphi.epidata.key'",
"",
"To save your key for later sessions (and hide it from your code), you can edit your .Renviron file with:",
"i" = "usethis::edit_r_environ()"
),
use_cli_format = TRUE,
.frequency = "regularly",
.frequency_id = "delphi.epidata.key"
)
Expand Down
28 changes: 14 additions & 14 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
#' @importFrom checkmate assert_character assert_integerish
#' @keywords internal
assert_character_param <- function(name, value, len = NULL, required = TRUE) {
null.ok <- !required
null_ok <- !required
assert_integerish(len, null.ok = TRUE, .var.name = "len")
assert_character(value, null.ok = null.ok, len = len, any.missing = FALSE, .var.name = name)
assert_character(value, null.ok = null_ok, len = len, any.missing = FALSE, .var.name = name)
}

#' Allows integer-like vectors
#' @importFrom checkmate assert_integerish
#' @keywords internal
assert_integerish_param <- function(name, value, len = NULL, required = TRUE) {
null.ok <- !required
null_ok <- !required
assert_integerish(len, null.ok = TRUE, .var.name = "len")
assert_integerish(value, null.ok = null.ok, len = len, any.missing = FALSE, .var.name = name)
assert_integerish(value, null.ok = null_ok, len = len, any.missing = FALSE, .var.name = name)
}

#' Allows a vector of date_like params: date, character, or integer-like
#' @importFrom checkmate check_date check_character check_integerish
#' @keywords internal
assert_date_param <- function(name, value, len = NULL, required = TRUE) {
null.ok <- !required
null_ok <- !required
assert_integerish(len, null.ok = TRUE, .var.name = "len")
assert(
check_date(value, len = len, any.missing = FALSE, null.ok = null.ok),
check_character(value, len = len, any.missing = FALSE, null.ok = null.ok),
check_integerish(value, len = len, any.missing = FALSE, null.ok = null.ok),
check_date(value, len = len, any.missing = FALSE, null.ok = null_ok),
check_character(value, len = len, any.missing = FALSE, null.ok = null_ok),
check_integerish(value, len = len, any.missing = FALSE, null.ok = null_ok),
combine = "or",
.var.name = name
)
Expand All @@ -36,19 +36,19 @@ assert_date_param <- function(name, value, len = NULL, required = TRUE) {
#' @importFrom checkmate assert check_character check_date check_integerish check_class check_list check_names
#' @keywords internal
assert_timeset_param <- function(name, value, len = NULL, required = TRUE) {
null.ok <- !required
null_ok <- !required
assert_integerish(len, len = 1L, null.ok = TRUE, .var.name = "len")
assert(
check_class(value, "EpiRange", null.ok = null.ok),
check_class(value, "EpiRange", null.ok = null_ok),
check_names(names(value), type = "unnamed"),
combine = "or",
.var.name = name
)
assert(
check_date(value, len = len, any.missing = FALSE, null.ok = null.ok),
check_character(value, len = len, any.missing = FALSE, null.ok = null.ok),
check_integerish(value, len = len, any.missing = FALSE, null.ok = null.ok),
check_class(value, "EpiRange", null.ok = null.ok),
check_date(value, len = len, any.missing = FALSE, null.ok = null_ok),
check_character(value, len = len, any.missing = FALSE, null.ok = null_ok),
check_integerish(value, len = len, any.missing = FALSE, null.ok = null_ok),
check_class(value, "EpiRange", null.ok = null_ok),
combine = "or",
.var.name = name
)
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.8.0"
version <- "0.9.0"
http_headers <- httr::add_headers("User-Agent" = paste0("epidatr/", version), "Accept-Encoding" = "gzip")
global_base_url <- "https://api.delphi.cmu.edu/epidata/"
Loading

0 comments on commit 7f2d73a

Please sign in to comment.