Skip to content

Commit 18de016

Browse files
authored
Merge pull request #173 from cmu-delphi/ar/release-fixes
A few more fixes for release
2 parents 09df128 + 8448da4 commit 18de016

25 files changed

+318
-159
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020
^.venv$
2121
^env$
2222
^.env$
23+
^README\.Rmd$
24+
^CRAN-SUBMISSION$

CRAN-SUBMISSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Version: 1.0.0
2+
Date: 2023-09-12 08:00:50 UTC
3+
SHA: 52436eb250eab1f9c70b250bf4ca1ab25cc48316

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Package: epidatr
22
Type: Package
33
Title: Client for Delphi's 'Epidata' API
44
Version: 1.0.0
5+
Date: 2023-09-11
56
Authors@R:
67
c(
78
person("Logan", "Brooks", email = "[email protected]", role = c("aut")),
@@ -15,9 +16,9 @@ Authors@R:
1516
person("George", "Haff", role = c("ctb")),
1617
person("Kathryn", "Mazaitis", role = c("ctb"))
1718
)
18-
URL: https://cmu-delphi.github.io/epidatr/, https://github.com/cmu-delphi/epidatr
19+
URL: https://cmu-delphi.github.io/epidatr/, https://cmu-delphi.github.io/delphi-epidata/, https://github.com/cmu-delphi/epidatr
1920
BugReports: https://github.com/cmu-delphi/epidatr/issues
20-
Description: The Delphi 'Epidata' API provides real-time access to epidemiological surveillance data for influenza, COVID-19, and other diseases for the USA at various geographical resolutions, both from official government sources such as the Center for Disease Control (CDC) and Google Trends and private partners such as Facebook and Change Healthcare. It is built and maintained by the Carnegie Mellon University Delphi research group.
21+
Description: The Delphi 'Epidata' API provides real-time access to epidemiological surveillance data for influenza, 'COVID-19', and other diseases for the USA at various geographical resolutions, both from official government sources such as the Center for Disease Control (CDC) and Google Trends and private partners such as Facebook and Change 'Healthcare'. It is built and maintained by the Carnegie Mellon University Delphi research group. To cite this API: David C. Farrow, Logan C. Brooks, Aaron 'Rumack', Ryan J. 'Tibshirani', 'Roni' 'Rosenfeld' (2015). Delphi 'Epidata' API. <https://github.com/cmu-delphi/delphi-epidata>.
2122
Depends: R (>= 3.5.0)
2223
License: MIT + file LICENSE
2324
Encoding: UTF-8

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ S3method(print,covidcast_data_signal_list)
77
S3method(print,covidcast_data_source)
88
S3method(print,covidcast_epidata)
99
S3method(print,epidata_call)
10-
export("%>%")
1110
export(avail_endpoints)
1211
export(cache_info)
1312
export(clear_cache)

R/cache.R

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ cache_environ$epidatr_cache <- NULL
6868
#' encoding of the call url. Each file corresponds to a unique epidata-API
6969
#' call.
7070
#' @examples
71-
#' \dontrun{
7271
#' set_cache(
73-
#' dir = "some/subdir",
72+
#' cache_dir = tempdir(),
7473
#' days = 14,
7574
#' max_size = 512,
76-
#' logfile = "some/subdir/logs.txt"
75+
#' logfile = "logs.txt"
7776
#' )
78-
#' }
7977
#'
8078
#' @param cache_dir the directory in which the cache is stored. By default, this
8179
#' is `tools::R_user_dir()` if on R 4.0+, but must be specified for earlier
@@ -92,6 +90,8 @@ cache_environ$epidatr_cache <- NULL
9290
#' variable is `EPIDATR_CACHE_LOGFILE`.
9391
#' @param confirm whether to confirm directory creation. default is `TRUE`;
9492
#' should only be set in non-interactive scripts
93+
#' @return [`NULL`] no return value, all effects are stored in the package
94+
#' environment
9595
#' @seealso [`clear_cache`] to delete the old cache while making a new one,
9696
#' [`disable_cache`] to disable without deleting, and [`cache_info`]
9797
#' @export
@@ -176,28 +176,23 @@ set_cache <- function(cache_dir = NULL,
176176
#' are using a session unique cache, you will have to pass the arguments you
177177
#' used for `set_cache` earlier, otherwise the system-wide `.Renviron`-based
178178
#' defaults will be used.
179-
#' @examples
180-
#' \dontrun{
181-
#' clear_cache(
182-
#' dir = "some/subdir",
183-
#' days = 14,
184-
#' max_size = 512,
185-
#' logfile = "some/subdir/logs.txt",
186-
#' )
187-
#' }
188179
#' @param disable instead of setting a new cache, disable caching entirely;
189180
#' defaults to `FALSE`
190181
#' @inheritDotParams set_cache
182+
#' @return [`NULL`] no return value, all effects are stored in the package
183+
#' environment
191184
#' @seealso [`set_cache`] to start a new cache (and general caching info),
192185
#' [`disable_cache`] to only disable without deleting, and [`cache_info`]
193186
#' @export
194187
#' @import cachem
195188
clear_cache <- function(disable = FALSE, ...) {
196-
cache_environ$epidatr_cache$destroy()
197-
if (!disable) {
198-
set_cache(...)
199-
} else {
189+
if (any(!is.na(cache_environ$epidatr_cache))) {
190+
cache_environ$epidatr_cache$destroy()
191+
}
192+
if (disable) {
200193
cache_environ$epidatr_cache <- NULL
194+
} else {
195+
set_cache(...)
201196
}
202197
}
203198

@@ -207,6 +202,8 @@ clear_cache <- function(disable = FALSE, ...) {
207202
#' the cache are untouched. If you are looking to disable the caching more
208203
#' permanently, set `EPIDATR_USE_CACHE=FALSE` as environmental variable in
209204
#' your `.Renviron`.
205+
#' @return [`NULL`] no return value, all effects are stored in the package
206+
#' environment
210207
#' @export
211208
#' @seealso [`set_cache`] to start a new cache (and general caching info),
212209
#' [`clear_cache`] to delete the cache and set a new one, and [`cache_info`]
@@ -220,6 +217,7 @@ disable_cache <- function() {
220217
#' @description
221218
#' Print out the information about the cache (as would be returned by cachem's
222219
#' `info()` method).
220+
#' @return [`list`] containing the info result as created by cachem
223221
#'
224222
#' @seealso [`set_cache`] to start a new cache (and general caching info),
225223
#' [`clear_cache`] to delete the cache and set a new one, and [`disable_cache`] to
@@ -239,7 +237,7 @@ cache_info <- function() {
239237
#' The guts of caching, its interposed between fetch and the specific fetch
240238
#' methods. Internal method only.
241239
#'
242-
#' @param call the `epidata_call` object
240+
#' @param epidata_call the `epidata_call` object
243241
#' @param fetch_args the args list for fetch as generated by [`fetch_args_list()`]
244242
#' @keywords internal
245243
#' @importFrom openssl md5

R/covidcast.R

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
#' turn a signal into a callable
2+
#' @param signal the signal of interest
3+
#' @param base_url the base url
4+
#' @keywords internal
15
parse_signal <- function(signal, base_url) {
26
class(signal) <- c("covidcast_data_signal", class(signal))
37
signal$key <- paste(signal$source, signal$signal, sep = ":")
48

59
#' fetch covidcast data
610
#'
7-
#' @param data_source data source to fetch
8-
#' @param signals data source to fetch
9-
#' @param geo_type geo_type to fetch
10-
#' @param time_type data source to fetch
11-
#' @param geo_values data source to fetch
12-
#' @param time_values data source to fetch
13-
#' @param as_of data source to fetch
14-
#' @param issues data source to fetch
15-
#' @param lag data source to fetch
16-
#' @return an instance of epidata_call
17-
#' @keywords internal
11+
#' param data_source data source to fetch
12+
#' param signals data source to fetch
13+
#' param geo_type geo_type to fetch
14+
#' param time_type data source to fetch
15+
#' param geo_values data source to fetch
16+
#' param time_values data source to fetch
17+
#' param as_of data source to fetch
18+
#' param issues data source to fetch
19+
#' param lag data source to fetch
20+
#' return an instance of epidata_call
21+
#' keywords internal
1822
signal$call <- function(geo_type,
1923
geo_values,
2024
time_values,

R/endpoints.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ pub_covidcast_meta <- function(fetch_args = fetch_args_list()) {
658658
#' signals = "confirmed_7dav_incidence_prop",
659659
#' geo_type = "state",
660660
#' time_type = "day",
661-
#' geo_values = "ca,fl",
661+
#' geo_values = c("ca", "fl"),
662662
#' time_values = epirange(20200601, 20200801)
663663
#' )
664664
#' pub_covidcast(
@@ -1102,11 +1102,13 @@ pub_fluview_meta <- function(fetch_args = fetch_args_list()) {
11021102
#' more information on ILINet, see
11031103
#' <https://gis.cdc.gov/grasp/fluview/fluportaldashboard.html>.
11041104
#'
1105-
#' @details The full list of location inputs can be accsssed at
1105+
#' @details The full list of location inputs can be accessed at
11061106
#' <https://github.com/cmu-delphi/delphi-epidata/blob/main/src/acquisition/fluview/fluview_locations.py>.
11071107
#'
11081108
#' @examples
1109-
#' pub_fluview(regions = "nat", epiweeks = epirange(201201, 202001))
1109+
#' \dontrun{
1110+
#' pub_fluview(regions = "nat", epiweeks = epirange(201201, 202005))
1111+
#' }
11101112
#' @param regions character. Locations to fetch. Can be any string IDs in
11111113
#' national, HHS region, census division, most states and territories, and so
11121114
#' on. Full list link below.
@@ -1492,7 +1494,7 @@ pvt_norostat <- function(auth, locations, epiweeks, fetch_args = fetch_args_list
14921494
#'
14931495
#' Obtains information on outpatient inluenza-like-illness (ILI) from Delphi's
14941496
#'
1495-
#' @details The full list of location inputs can be accsssed at
1497+
#' @details The full list of location inputs can be accessed at
14961498
#' <https://github.com/cmu-delphi/delphi-epidata/blob/main/src/acquisition/fluview/fluview_locations.py>.
14971499
#'
14981500
#' @examples

R/utils-pipe.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,2 @@
1-
#' Pipe operator
2-
#'
3-
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
4-
#'
5-
#' @name %>%
6-
#' @rdname pipe
7-
#' @keywords internal
8-
#' @export
91
#' @importFrom magrittr %>%
10-
#' @usage lhs \%>\% rhs
11-
#' @param lhs A value or the magrittr placeholder.
12-
#' @param rhs A function call using the magrittr semantics.
13-
#' @return The result of calling `rhs(lhs)`.
142
NULL

README.Rmd

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
output: github_document
3+
---
4+
5+
<!-- README.md is generated from README.Rmd. Please edit that file -->
6+
7+
```{r, include = FALSE}
8+
knitr::opts_chunk$set(
9+
collapse = TRUE,
10+
comment = "#>",
11+
fig.path = "man/figures/README-",
12+
out.width = "100%"
13+
)
14+
ggplot2::theme_set(ggplot2::theme_bw())
15+
```
16+
17+
# Delphi Epidata R client
18+
19+
20+
<!-- badges: start -->
21+
[![License: MIT][mit-image]][mit-url] [![Github Actions][github-actions-image]][github-actions-url]
22+
[![codecov](https://codecov.io/gh/dsweber2/epidatr/branch/dev/graph/badge.svg?token=jVHL9eHZNZ)](https://app.codecov.io/gh/dsweber2/epidatr)
23+
<!-- badges: end -->
24+
25+
26+
27+
The [Delphi Epidata API](https://cmu-delphi.github.io/delphi-epidata/) provides real-time access to epidemiological surveillance data for influenza, COVID-19, and other diseases for the USA at various geographical resolutions, both from official government sources such as the [Center for Disease Control (CDC)](https://www.cdc.gov/datastatistics/index.html) and [Google Trends](https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/google-symptoms.html) and private partners such as [Facebook](https://delphi.cmu.edu/blog/2020/08/26/covid-19-symptom-surveys-through-facebook/) and [Change Healthcare](https://www.changehealthcare.com/). It is built and maintained by the Carnegie Mellon University [Delphi research group](https://delphi.cmu.edu/).
28+
29+
This package is designed to streamline the downloading and usage of data from the [Delphi Epidata
30+
API](https://cmu-delphi.github.io/delphi-epidata/). It provides a simple R interface to the API, including functions for downloading data, parsing the results, and converting the data into a tidy format. The API stores a historical record of all data, including corrections and updates, which is particularly useful for accurately backtesting forecasting models. We also provide packages for downstream data processing ([epiprocess](https://github.com/cmu-delphi/epiprocess)) and modeling ([epipredict](https://github.com/cmu-delphi/epipredict)).
31+
32+
## Usage
33+
34+
```{r}
35+
library(epidatr)
36+
# Obtain the smoothed covid-like illness (CLI) signal from the
37+
# Facebook survey as it was on April 10, 2021 for the US
38+
epidata <- pub_covidcast(
39+
source = "fb-survey",
40+
signals = "smoothed_cli",
41+
geo_type = "nation",
42+
time_type = "day",
43+
geo_values = "us",
44+
time_values = epirange(20210101, 20210601),
45+
as_of = "2021-06-01"
46+
)
47+
epidata
48+
```
49+
50+
```{r fb-cli-signal}
51+
# Plot this data
52+
library(ggplot2)
53+
ggplot(epidata, aes(x = time_value, y = value)) +
54+
geom_line() +
55+
labs(
56+
title = "Smoothed CLI from Facebook Survey",
57+
subtitle = "US, 2021",
58+
x = "Date",
59+
y = "CLI"
60+
)
61+
```
62+
63+
64+
## Installation
65+
66+
Install from GitHub:
67+
68+
```R
69+
# Install the dev version using `pak` or `remotes`
70+
pak::pkg_install("cmu-delphi/epidatr")
71+
remotes::install_github("cmu-delphi/epidatr")
72+
```
73+
74+
CRAN version coming soon.
75+
76+
### API Keys
77+
78+
The Delphi API requires a (free) API key for full functionality. To generate
79+
your key, register for a pseudo-anonymous account
80+
[here](https://api.delphi.cmu.edu/epidata/admin/registration_form) and see more
81+
discussion on the [general API
82+
website](https://cmu-delphi.github.io/delphi-epidata/api/api_keys.html). The
83+
`epidatr` client will automatically look for this key in the R option
84+
`delphi.epidata.key` or in the environment variable
85+
`DELPHI_EPIDATA_KEY`. We recommend storing your key in `.Renviron` file, which R
86+
will read by default.
87+
88+
Note that for the time being, the private endpoints (i.e. those prefixed with
89+
`pvt`) will require a separate key that needs to be passed as an argument.
90+
91+
[mit-image]: https://img.shields.io/badge/License-MIT-yellow.svg
92+
[mit-url]: https://opensource.org/license/mit/
93+
[github-actions-image]: https://github.com/cmu-delphi/epidatr/workflows/ci/badge.svg
94+
[github-actions-url]: https://github.com/cmu-delphi/epidatr/actions
95+
96+
## Get updates
97+
98+
You should consider subscribing to the [API mailing list](https://lists.andrew.cmu.edu/mailman/listinfo/delphi-covidcast-api) to be notified of package updates, new data sources, corrections, and other updates.
99+
100+
## For users of the `covidcast` R package
101+
102+
The `epidatr` package is a complete rewrite of the [`covidcast` package](https://cmu-delphi.github.io/covidcast/covidcastR/), with a focus on speed, reliability, and ease of use. The `covidcast` package is deprecated and will no longer be updated.

0 commit comments

Comments
 (0)