From b29560dcbb3b16d875c94c3e77e8e6a658a6c203 Mon Sep 17 00:00:00 2001 From: nmdefries <42820733+nmdefries@users.noreply.github.com> Date: Wed, 17 Sep 2025 10:48:01 -0400 Subject: [PATCH 1/3] add rvdss endpoint and basic tests --- R/endpoints.R | 149 ++++++++++++++++++++++++++++++++ tests/testthat/test-endpoints.R | 13 +++ 2 files changed, 162 insertions(+) diff --git a/R/endpoints.R b/R/endpoints.R index 1f789d18..def6da8a 100644 --- a/R/endpoints.R +++ b/R/endpoints.R @@ -2036,6 +2036,155 @@ pvt_quidel <- function( ) %>% fetch(fetch_args = fetch_args) } +#' Canadian respiratory virus surveillance report +#' +#' @description +#' API docs: +#' +#' Data is weekly. +#' +#' @examples +#' \dontrun{ +#' pub_rvdss( +#' geo_type = "province", +#' geo_values = c("yu", "on"), +#' time_values = epirange(20200601, 20200801) +#' ) +#' pub_rvdss( +#' geo_type = "province", +#' geo_values = "*", +#' time_values = epirange(20200601, 20200801) +#' ) +#' } +#' +#' @param geo_type string. The geographic resolution of the data. Levels available: +#' "nation", "region", "province", "lab". +#' @param geo_values character. The geographies to return. Defaults to all +#' ("*") geographies within requested geographic resolution. "nation" and "province" +#' locations use standard 2-letter abbreviations (e.g. "on"). Available regions are +#' "atlantic", "bc", "on", "prairies", "qc", and "territories." "lab"s are full +#' facility names. +#' @param time_values [`timeset`]. Dates to fetch. Defaults to all ("*") dates. +#' @param ... not used for values, forces later arguments to bind by name +#' @param as_of Date. Optionally, the as of date for the issues to fetch. If not +#' specified, the most recent data is returned. Mutually exclusive with +#' `issues` or `lag`. +#' @param issues [`timeset`]. Optionally, the issue of the data to fetch. If not +#' specified, the most recent issue is returned. Mutually exclusive with +#' `as_of` or `lag`. +#' @param fetch_args [`fetch_args`]. Additional arguments to pass to `fetch()`. +#' @return [`tibble::tibble`] +#' +#' @seealso [pub_covidcast_meta()], [covidcast_epidata()], [epirange()] +#' @keywords endpoint +#' @export +pub_rvdss <- function( + geo_type, + geo_values = "*", + time_values = "*", + ..., + as_of = NULL, + issues = NULL, + fetch_args = fetch_args_list()) { + rlang::check_dots_empty() + + # Check parameters + if (missing(geo_type)) { + cli::cli_abort( + "`geo_type` is required", + class = "epidatr__pub_rvdss__missing_required_args" + ) + } + + if (sum(!is.null(issues), !is.null(as_of)) > 1) { + cli::cli_abort( + "`issues` and `as_of` are mutually exclusive", + class = "epidatr__pub_rvdss__too_many_issue_params" + ) + } + + assert_character_param("geo_type", geo_type, len = 1) + assert_timeset_param("time_values", time_values) + assert_character_param("geo_values", geo_values) + assert_date_param("as_of", as_of, len = 1, required = FALSE) + assert_timeset_param("issues", issues, required = FALSE) + time_values <- parse_timeset_input(time_values) + as_of <- parse_timeset_input(as_of) + issues <- parse_timeset_input(issues) + + create_epidata_call( + "covidcast/", + list( + geo_type = geo_type, + geo_values = geo_values, + time_values = time_values, + as_of = as_of, + issues = issues + ), + list( + # descriptive fields + create_epidata_field_info( + "geo_type", + "categorical", + categories = c("nation", "region", "province", "lab") + ), + create_epidata_field_info("geo_value", "text"), + create_epidata_field_info("region", "text"), + create_epidata_field_info( + "time_type", + "categorical", + categories = c("week") + ), + create_epidata_field_info("epiweek", "epiweek"), # Stored as an int in YYYYWW format + create_epidata_field_info("time_value", "epiweek"), # Stored as a date + create_epidata_field_info("issue", "epiweek"), # Stored as a date + create_epidata_field_info("week", "int"), + create_epidata_field_info("weekorder", "int"), + create_epidata_field_info("year", "int"), + + # value fields + create_epidata_field_info("adv_pct_positive", "float"), + create_epidata_field_info("adv_positive_tests", "float"), + create_epidata_field_info("adv_tests", "float"), + create_epidata_field_info("evrv_pct_positive", "float"), + create_epidata_field_info("evrv_positive_tests", "float"), + create_epidata_field_info("evrv_tests", "float"), + create_epidata_field_info("flu_pct_positive", "float"), + create_epidata_field_info("flu_positive_tests", "float"), + create_epidata_field_info("flu_tests", "float"), + create_epidata_field_info("flua_pct_positive", "float"), + create_epidata_field_info("flua_positive_tests", "float"), + create_epidata_field_info("flua_tests", "float"), + create_epidata_field_info("fluah1n1pdm09_positive_tests", "float"), + create_epidata_field_info("fluah3_positive_tests", "float"), + create_epidata_field_info("fluauns_positive_tests", "float"), + create_epidata_field_info("flub_pct_positive", "float"), + create_epidata_field_info("flub_positive_tests", "float"), + create_epidata_field_info("flub_tests", "float"), + create_epidata_field_info("hcov_pct_positive", "float"), + create_epidata_field_info("hcov_positive_tests", "float"), + create_epidata_field_info("hcov_tests", "float"), + create_epidata_field_info("hmpv_pct_positive", "float"), + create_epidata_field_info("hmpv_positive_tests", "float"), + create_epidata_field_info("hmpv_tests", "float"), + create_epidata_field_info("hpiv1_positive_tests", "float"), + create_epidata_field_info("hpiv2_positive_tests", "float"), + create_epidata_field_info("hpiv3_positive_tests", "float"), + create_epidata_field_info("hpiv4_positive_tests", "float"), + create_epidata_field_info("hpiv_pct_positive", "float"), + create_epidata_field_info("hpiv_positive_tests", "float"), + create_epidata_field_info("hpiv_tests", "float"), + create_epidata_field_info("hpivother_positive_tests", "float"), + create_epidata_field_info("rsv_pct_positive", "float"), + create_epidata_field_info("rsv_positive_tests", "float"), + create_epidata_field_info("rsv_tests", "float"), + create_epidata_field_info("sarscov2_pct_positive", "float"), + create_epidata_field_info("sarscov2_positive_tests", "float"), + create_epidata_field_info("sarscov2_tests", "float") + ) + ) %>% fetch(fetch_args = fetch_args) +} + #' Influenza and dengue digital surveillance sensors #' @description #' API docs: diff --git a/tests/testthat/test-endpoints.R b/tests/testthat/test-endpoints.R index e29acb12..f527e3dd 100644 --- a/tests/testthat/test-endpoints.R +++ b/tests/testthat/test-endpoints.R @@ -127,6 +127,12 @@ test_that("basic_epidata_call", { epiweeks = epirange(201201, 202001), fetch_args = fetch_args_list(dry_run = TRUE) ) %>% request_url()) + expect_no_error(pub_rvdss( + geo_type = "nation", + time_values = epirange(20200601, 20200801), + geo_values = "ca", + fetch_args = fetch_args_list(dry_run = TRUE) + ) %>% request_url()) expect_no_error(pvt_sensors( auth = "yourkey", names = "sar3", @@ -325,6 +331,13 @@ test_that("endoints accept wildcard for date parameter", { epiweeks = "*", fetch_args = fetch_args_list(dry_run = TRUE) )) + expect_no_error(call <- pub_rvdss( + geo_type = "province", + time_values = "*", + geo_values = "*", + fetch_args = fetch_args_list(dry_run = TRUE) + )) + expect_identical(call$params$epiweeks$from, 100001) expect_identical(call$params$epiweeks$to, 300001) From d23aa04f613785f46c1798ee671659e9d61f43b7 Mon Sep 17 00:00:00 2001 From: nmdefries Date: Wed, 17 Sep 2025 14:53:51 +0000 Subject: [PATCH 2/3] docs: document (GHA) --- DESCRIPTION | 2 +- NAMESPACE | 1 + man/pub_rvdss.Rd | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 man/pub_rvdss.Rd diff --git a/DESCRIPTION b/DESCRIPTION index ad1d2f35..c32a6132 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -68,7 +68,7 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Collate: 'auth.R' 'avail_endpoints.R' diff --git a/NAMESPACE b/NAMESPACE index 19eefb85..1e5648ae 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -38,6 +38,7 @@ export(pub_nidss_dengue) export(pub_nidss_flu) export(pub_nowcast) export(pub_paho_dengue) +export(pub_rvdss) export(pub_wiki) export(pvt_cdc) export(pvt_dengue_sensors) diff --git a/man/pub_rvdss.Rd b/man/pub_rvdss.Rd new file mode 100644 index 00000000..5a43cfef --- /dev/null +++ b/man/pub_rvdss.Rd @@ -0,0 +1,67 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/endpoints.R +\name{pub_rvdss} +\alias{pub_rvdss} +\title{Canadian respiratory virus surveillance report} +\usage{ +pub_rvdss( + geo_type, + geo_values = "*", + time_values = "*", + ..., + as_of = NULL, + issues = NULL, + fetch_args = fetch_args_list() +) +} +\arguments{ +\item{geo_type}{string. The geographic resolution of the data. Levels available: +"nation", "region", "province", "lab".} + +\item{geo_values}{character. The geographies to return. Defaults to all +("*") geographies within requested geographic resolution. "nation" and "province" +locations use standard 2-letter abbreviations (e.g. "on"). Available regions are +"atlantic", "bc", "on", "prairies", "qc", and "territories." "lab"s are full +facility names.} + +\item{time_values}{\code{\link{timeset}}. Dates to fetch. Defaults to all ("*") dates.} + +\item{...}{not used for values, forces later arguments to bind by name} + +\item{as_of}{Date. Optionally, the as of date for the issues to fetch. If not +specified, the most recent data is returned. Mutually exclusive with +\code{issues} or \code{lag}.} + +\item{issues}{\code{\link{timeset}}. Optionally, the issue of the data to fetch. If not +specified, the most recent issue is returned. Mutually exclusive with +\code{as_of} or \code{lag}.} + +\item{fetch_args}{\code{\link{fetch_args}}. Additional arguments to pass to \code{fetch()}.} +} +\value{ +\code{\link[tibble:tibble]{tibble::tibble}} +} +\description{ +API docs: \url{https://cmu-delphi.github.io/delphi-epidata/api/rvdss.html} + +Data is weekly. +} +\examples{ +\dontrun{ +pub_rvdss( + geo_type = "province", + geo_values = c("yu", "on"), + time_values = epirange(20200601, 20200801) +) +pub_rvdss( + geo_type = "province", + geo_values = "*", + time_values = epirange(20200601, 20200801) +) +} + +} +\seealso{ +\code{\link[=pub_covidcast_meta]{pub_covidcast_meta()}}, \code{\link[=covidcast_epidata]{covidcast_epidata()}}, \code{\link[=epirange]{epirange()}} +} +\keyword{endpoint} From 45ea83fa2fb3836380c66a2d704cc436869f45c9 Mon Sep 17 00:00:00 2001 From: nmdefries <42820733+nmdefries@users.noreply.github.com> Date: Wed, 17 Sep 2025 10:57:28 -0400 Subject: [PATCH 3/3] news and version --- DESCRIPTION | 2 +- NEWS.md | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c32a6132..f818e50d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: epidatr Title: Client for Delphi's 'Epidata' API -Version: 1.2.1 +Version: 1.2.2 Authors@R: c( person("Logan", "Brooks", , "lcbrooks@andrew.cmu.edu", role = "aut"), person("Dmitry", "Shemetov", , "dshemeto@andrew.cmu.edu", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 38c3c8b5..356e5ea7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,14 @@ -# epidatr 1.2.1 +# epidatr 1.3.0 + +## Changes + +## Features + +- Add `rvdss` endpoint, which gives access to Canadian national, regional, + provincial, and lab-level respiratory disease data. + ## Patches + - Fix so that `covidcast_epidata()` will still print if fields are missing. # epidatr 1.2.0 @@ -14,10 +23,6 @@ - `missing` doesn't count default values as non-missing. If a user doesn't pass `geo_values` or `time_values` (both of which default to `"*"` in `pub_covidcast`), or `dates` (in `pub_covid_hosp_state_timeseries`), the missing check fails. To avoid this, just don't check missingness of those two arguments. - `fetch_args_list` now has an `refresh_cache` argument, which is `FALSE` by default. -# epidatr 1.1.1 - -## Changes - ## Features ## Patches