Skip to content

Commit 7a5bcb7

Browse files
authored
Merge pull request #149 from cmu-delphi/docs-review
Docs review
2 parents f9166b8 + 67dd3d1 commit 7a5bcb7

38 files changed

+276
-118
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Authors@R:
99
person("David", "Weber", email = "[email protected]", role = c("ctb")),
1010
person("Samuel", "Gratzl", email = "[email protected]", role = c("aut"))
1111
)
12-
URL: https://github.com/cmu-delphi/epidatr
12+
URL: https://cmu-delphi.github.io/epidatr/, https://github.com/cmu-delphi/epidatr
1313
BugReports: https://github.com/cmu-delphi/epidatr/issues
1414
Description: R Client for Delphi's Epidata API. Tools for fetching data in various forms.
1515
Depends: R (>= 3.5.0)

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export(covid_hosp_facility)
1010
export(covid_hosp_facility_lookup)
1111
export(covid_hosp_state_timeseries)
1212
export(covidcast)
13+
export(covidcast_epidata)
1314
export(covidcast_meta)
1415
export(delphi)
1516
export(dengue_nowcast)

R/check.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ assert_date_param <- function(name, value, len = NULL, required = TRUE) {
3434
#' Allows a timeset param: a date vector, a character vector, an integer-like
3535
#' vector, or a single EpiRange
3636
#' @importFrom checkmate assert check_character check_date check_integerish check_class check_list check_names
37+
#' @keywords internal
3738
assert_timeset_param <- function(name, value, len = NULL, required = TRUE) {
3839
null.ok <- !required
3940
assert_integerish(len, len = 1L, null.ok = TRUE, .var.name = "len")

R/covidcast.R

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ parse_signal <- function(signal, base_url) {
1414
#' @param issues data source to fetch
1515
#' @param lag data source to fetch
1616
#' @return an instance of epidata_call
17+
#' @keywords internal
1718
signal$call <- function(geo_type,
1819
geo_values,
1920
time_values,
@@ -31,10 +32,10 @@ parse_signal <- function(signal, base_url) {
3132
}
3233

3334
#' @export
34-
print.covidcast_data_signal <- function(signal, ...) {
35-
print(signal$name)
36-
print(signal$key)
37-
print(signal$short_description)
35+
print.covidcast_data_signal <- function(x, ...) {
36+
print(x$name)
37+
print(x$key)
38+
print(x$short_description)
3839
}
3940

4041
parse_source <- function(source, base_url) {
@@ -78,26 +79,26 @@ as.data.frame.covidcast_data_signal_list <- function(signals, ...) {
7879
}
7980

8081
#' @export
81-
print.covidcast_data_source <- function(source, ...) {
82-
print(source$name, ...)
83-
print(source$source, ...)
84-
print(source$description, ...)
85-
signals <- as.data.frame(source$signals)
82+
print.covidcast_data_source <- function(x, ...) {
83+
print(x$name, ...)
84+
print(x$source, ...)
85+
print(x$description, ...)
86+
signals <- as.data.frame(x$signals)
8687
print(signals[, c("signal", "name", "short_description")], ...)
8788
}
8889

89-
#' creates the covidcast epidata helper
90+
#' Creates the COVIDcast Epidata autocomplete helper
9091
#'
91-
#' Creates a helper object that can use auto-complete to help find covidcast
92+
#' Creates a helper object that can use auto-complete to help find COVIDcast
9293
#' sources and signals.
9394
#'
9495
#' @param base_url optional alternative API base url
9596
#' @param timeout_seconds the maximum amount of time to wait for a response
9697
#' @importFrom httr stop_for_status content http_type
9798
#' @importFrom jsonlite fromJSON
9899
#' @importFrom xml2 read_html xml_find_all xml_text
99-
#' @return an instance of covidcast_epidata
100-
#'
100+
#' @return An instance of `covidcast_epidata`
101+
#' @export
101102
covidcast_epidata <- function(base_url = global_base_url, timeout_seconds = 30) {
102103
url <- join_url(base_url, "covidcast/meta")
103104
response <- do_request(url, list(), timeout_seconds)
@@ -154,16 +155,16 @@ as.data.frame.covidcast_data_source_list <- function(sources, ...) {
154155
}), ...)
155156
}
156157

157-
print.covidcast_epidata <- function(epidata, ...) {
158+
print.covidcast_epidata <- function(x, ...) {
158159
print("COVIDcast Epidata Fetcher")
159160
print("Sources:")
160-
sources <- as.data.frame(epidata$sources)
161+
sources <- as.data.frame(x$sources)
161162
print(sources[1:5, c("source", "name")], ...)
162163
if (nrow(sources) > 5) {
163164
print(paste0((nrow(sources) - 5), " more..."))
164165
}
165166
print("Signals")
166-
signals <- as.data.frame(epidata$signals)
167+
signals <- as.data.frame(x$signals)
167168
print(signals[1:5, c("source", "signal", "name")], ...)
168169
if (nrow(signals) > 5) {
169170
print(paste0((nrow(signals) - 5), " more..."))

R/endpoints.R

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Fetch CDC page hits
22
#'
3-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/cdc.html
3+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/cdc.html>
44
#'
55
#' @examples
66
#' \dontrun{
@@ -640,10 +640,10 @@ covidcast_meta <- function() {
640640
#' time_values = epirange(20200601, 20200801)
641641
#' ) %>% fetch()
642642
#' }
643-
#' @param data_source string. The data source to query (see:
643+
#' @param source string. The data source to query (see:
644644
#' <https://cmu-delphi.github.io/delphi-epidata/api/covidcast_signals.html>).
645645
#' @param signals string. The signals to query from a specific source (see:
646-
#' <https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals.html>).
646+
#' <https://cmu-delphi.github.io/delphi-epidata/api/covidcast_signals.html>).
647647
#' @param geo_type string. The geographic resolution of the data (see:
648648
#' <https://cmu-delphi.github.io/delphi-epidata/api/covidcast_geography.html>).
649649
#' @param time_type string. The temporal resolution of the data (either "day" or
@@ -685,7 +685,7 @@ covidcast <- function(
685685
missing(time_values) || missing(geo_values)
686686
) {
687687
stop(
688-
"`data_source`, `signals`, `time_type`, `geo_type`, `time_values`, and `geo_value` are all required"
688+
"`source`, `signals`, `time_type`, `geo_type`, `time_values`, and `geo_value` are all required"
689689
)
690690
}
691691

@@ -748,7 +748,7 @@ covidcast <- function(
748748

749749
#' Fetch Delphi's ILINet forecasts
750750
#'
751-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/delphi.html
751+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/delphi.html>
752752
#'
753753
#' @examples
754754
#' \dontrun{
@@ -778,7 +778,7 @@ delphi <- function(system, epiweek) {
778778

779779
#' Fetch Delphi's PAHO Dengue nowcast
780780
#'
781-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/dengue_nowcast.html
781+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/dengue_nowcast.html>
782782
#'
783783
#' TODO: what are valid locations here?
784784
#' @examples
@@ -813,7 +813,7 @@ dengue_nowcast <- function(locations, epiweeks) {
813813
#' Fetch Delphi's digital surveillance sensors for dengue in PAHO member
814814
#' countries
815815
#'
816-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/dengue_sensors.html
816+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/dengue_sensors.html>
817817
#'
818818
#' TODO: what are valid locations and names?
819819
#' @examples
@@ -970,7 +970,7 @@ flusurv <- function(locations, epiweeks, issues = NULL, lag = NULL) {
970970

971971
#' Fetch FluView virological data from clinical labs
972972
#'
973-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/fluview_clinical.html
973+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/fluview_clinical.html>
974974
#'
975975
#' @examples
976976
#' \dontrun{
@@ -1024,7 +1024,7 @@ fluview_clinical <- function(regions, epiweeks, issues = NULL, lag = NULL) {
10241024

10251025
#' Fetch FluView metadata
10261026
#'
1027-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/fluview_meta.html
1027+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/fluview_meta.html>
10281028
#' @examples
10291029
#' \dontrun{
10301030
#' fluview_meta() %>% fetch()
@@ -1159,7 +1159,7 @@ gft <- function(locations, epiweeks) {
11591159

11601160
#' Fetch Google Health Trends data
11611161
#'
1162-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/ght.html
1162+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/ght.html>
11631163
#'
11641164
#' TODO: find a non-trivial query
11651165
#' @examples
@@ -1203,7 +1203,7 @@ pvt_ght <- function(auth, locations, epiweeks, query) {
12031203

12041204
#' Fetch KCDC data
12051205
#'
1206-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/kcdc_ili.html
1206+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/kcdc_ili.html>
12071207
#'
12081208
#' TODO: find a non-trivial region
12091209
#' @examples
@@ -1251,7 +1251,7 @@ kcdc_ili <- function(regions, epiweeks, issues = NULL, lag = NULL) {
12511251

12521252
#' Fetch NoroSTAT metadata
12531253
#'
1254-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/meta_norostat.html
1254+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/meta_norostat.html>
12551255
#'
12561256
#' @examples
12571257
#' \dontrun{
@@ -1269,7 +1269,7 @@ pvt_meta_norostat <- function(auth) {
12691269

12701270
#' Fetch api metadata
12711271
#'
1272-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/meta.html
1272+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/meta.html>
12731273
#'
12741274
#' @return [`epidata_call`]
12751275
#'
@@ -1371,7 +1371,7 @@ nidss_flu <- function(regions, epiweeks, issues = NULL, lag = NULL) {
13711371

13721372
#' Fetch NoroSTAT data (point data, no min/max)
13731373
#'
1374-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/norostat.html
1374+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/norostat.html>
13751375
#'
13761376
#' @examples
13771377
#' \dontrun{
@@ -1446,7 +1446,7 @@ nowcast <- function(locations, epiweeks) {
14461446

14471447
#' Fetch PAHO Dengue
14481448
#'
1449-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/paho_dengue.html
1449+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/paho_dengue.html>
14501450
#'
14511451
#' @examples
14521452
#' \dontrun{
@@ -1495,7 +1495,7 @@ paho_dengue <- function(regions, epiweeks, issues = NULL, lag = NULL) {
14951495

14961496
#' Fetch Quidel COVID-19 and influenza testing data
14971497
#'
1498-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/quidel.html
1498+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/quidel.html>
14991499
#'
15001500
#' @examples
15011501
#' \dontrun{
@@ -1534,7 +1534,7 @@ pvt_quidel <- function(auth, locations, epiweeks) {
15341534

15351535
#' Fetch Delphi's digital surveillance sensors
15361536
#'
1537-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/sensors.html
1537+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/sensors.html>
15381538
#'
15391539
#' @examples
15401540
#' \dontrun{
@@ -1578,7 +1578,7 @@ pvt_sensors <- function(auth, names, locations, epiweeks) {
15781578

15791579
#' Fetch HealthTweets data
15801580
#'
1581-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/twitter.html
1581+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/twitter.html>
15821582
#'
15831583
#' @examples
15841584
#' \dontrun{
@@ -1628,7 +1628,7 @@ pvt_twitter <- function(auth, locations, dates = NULL, epiweeks = NULL) {
16281628

16291629
#' Fetch Wikipedia access data
16301630
#'
1631-
#' API docs: https://cmu-delphi.github.io/delphi-epidata/api/wiki.html
1631+
#' API docs: <https://cmu-delphi.github.io/delphi-epidata/api/wiki.html>
16321632
#'
16331633
#' @examples
16341634
#' \dontrun{

R/epidatacall.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ request_arguments <- function(epidata_call, format_type, fields = NULL) {
8989
}
9090

9191
#' @export
92-
print.epidata_call <- function(epidata_call) {
93-
stopifnot(inherits(epidata_call, "epidata_call"))
92+
print.epidata_call <- function(x, ...) {
93+
stopifnot(inherits(x, "epidata_call"))
9494
cli::cli_h1("<epidata_call> object:")
9595
cli::cli_bullets(c(
9696
"*" = "Pipe this object into `fetch()` to actually fetch the data",
97-
"*" = paste0("Request URL: ", request_url(epidata_call))
97+
"*" = paste0("Request URL: ", request_url(x))
9898
))
9999
}
100100

@@ -264,6 +264,7 @@ with_base_url <- function(epidata_call, base_url) {
264264
#' HTTP errors and forwarding the HTTP body in R errors
265265
#' @importFrom httr stop_for_status content http_type
266266
#' @importFrom xml2 read_html xml_find_all xml_text
267+
#' @keywords internal
267268
request_impl <- function(epidata_call, format_type, fields = NULL, timeout_seconds = 30) {
268269
stopifnot(inherits(epidata_call, "epidata_call"))
269270
stopifnot(format_type %in% c("json", "csv", "classic"))

R/epidatr-package.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
#' Delphi Epidata
2-
#'
3-
#' TODO
4-
#'
5-
#' @docType package
6-
#' @name epidatr
7-
NULL
1+
#' @keywords internal
2+
"_PACKAGE"

R/model.R

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
#' builds a new EpiRange instances
1+
#' Specify a date range (in days or epiweeks) for an API request.
22
#'
3-
#' @param from A Date, integer-like value, or integer-like string that takes the
4-
#' form YYYYMMDD for dates or YYYYMM for epiweeks.
5-
#' @param to A Date, integer-like value, or integer-like string that takes the
6-
#' form YYYYMMDD for dates or YYYYMM for epiweeks.
3+
#' Epiweeks, also known as MMWR weeks number the weeks of the year from 1 to 53,
4+
#' each week spanning from Sunday to Saturday. The numbering is [defined by the
5+
#' CDC](https://ndc.services.cdc.gov/wp-content/uploads/MMWR_Week_overview.pdf).
6+
#'
7+
#' @param from A `Date`, integer-like value, or integer-like string that takes the
8+
#' form YYYYMMDD for dates or YYYYWW for epiweeks.
9+
#' @param to A `Date`, integer-like value, or integer-like string that takes the
10+
#' form YYYYMMDD for dates or YYYYWW for epiweeks.
711
#' @return EpiRange instance
812
#' @importFrom checkmate check_integerish check_character check_date assert
913
#'
14+
#' @examples
15+
#' # Represents 2021-01-01 to 2021-01-07, inclusive
16+
#' epirange(20210101, 20210107)
17+
#'
18+
#' # The same, but using Date objects
19+
#' epirange(as.Date("2021-01-01"), as.Date("2021-01-07"))
20+
#'
21+
#' # Represents epiweeks 2 through 4 of 2022, inclusive
22+
#' epirange(202202, 202204)
1023
#' @export
1124
epirange <- function(from, to) {
1225
assert(
@@ -47,21 +60,25 @@ epirange <- function(from, to) {
4760

4861
#' timeset
4962
#'
50-
#' A collection of date-like values, including dates, epiweeks, and ranges of
51-
#' dates or epiweeks ([`epirange`]). This is often used to specify the time
52-
#' dimension for an epidata query. The allowed values are:
63+
#' Many API calls accept timesets to specify the time ranges of data being
64+
#' requested. Timesets can be specified with `epirange()`, as `Date` objects, or
65+
#' with wildcards.
66+
#'
67+
#' Timesets are not special R types; the term simply describes any value that
68+
#' would be accepted by epidatr to specify the time value of an epidata query.
69+
#' The allowed values are:
5370
#'
5471
#' - Dates: `Date` instances, integer-like values, or integer-like strings that
55-
#' take the form YYYYMMDD,
56-
#' - Epiweeks: integer-like values or integer-like strings that take the form
57-
#' YYYYMM,
58-
#' - EpiRanges: a list of [`epirange`] instances.
59-
#' - Wildcard: "*" (requests all available values for this dimension)
72+
#' take the form YYYYMMDD.
73+
#' - Epiweeks: Integer-like values or integer-like strings that take the form
74+
#' YYYYWW.
75+
#' - EpiRanges: A range returned by `epirange()`, or a list of multiple ranges
76+
#' - Wildcard: The string `"*"`, which request all available time values
6077
#'
6178
#' Please refer to the specific endpoint documentation for guidance on using
6279
#' dates vs weeks. Most endpoints support only one or the other. Some (less
6380
#' commonly used) endpoints may not accept the `"*"` wildcard, but this can be
64-
#' simulated with a large [`epirange`].
81+
#' simulated with a large `epirange()`.
6582
#'
6683
#' @name timeset
6784
NULL

R/request.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ join_url <- function(url, endpoint) {
2121
#' }
2222
#'
2323
#' @importFrom httr RETRY
24+
#' @keywords internal
2425
do_request <- function(url, params, timeout_seconds = 30) {
2526
# don't retry in case of certain status codes
2627
res <- httr::RETRY("GET",

0 commit comments

Comments
 (0)