Skip to content

Commit cf7c391

Browse files
committed
Make the autocomplete helper public and document it better
1 parent 8e45a6a commit cf7c391

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

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/covidcast.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ print.covidcast_data_source <- function(x, ...) {
8787
print(signals[, c("signal", "name", "short_description")], ...)
8888
}
8989

90-
#' creates the covidcast epidata helper
90+
#' Creates the COVIDcast Epidata autocomplete helper
9191
#'
92-
#' 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
9393
#' sources and signals.
9494
#'
9595
#' @param base_url optional alternative API base url
9696
#' @param timeout_seconds the maximum amount of time to wait for a response
9797
#' @importFrom httr stop_for_status content http_type
9898
#' @importFrom jsonlite fromJSON
9999
#' @importFrom xml2 read_html xml_find_all xml_text
100-
#' @return an instance of covidcast_epidata
101-
#'
100+
#' @return An instance of `covidcast_epidata`
101+
#' @export
102102
covidcast_epidata <- function(base_url = global_base_url, timeout_seconds = 30) {
103103
url <- join_url(base_url, "covidcast/meta")
104104
response <- do_request(url, list(), timeout_seconds)

man/covidcast_epidata.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/epidatr.Rmd

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,33 @@ Examples queries with all the endpoint functions available in this package are g
6262

6363
## Advanced Usage (Experimental)
6464

65-
You can use `covidcast_epidata` to get help with finding sources and functions without leaving R.
66-
Using tab completion after typing `epidata$signals$` below, you can see all the available sources and signals in the API, with the format `source:signal`.
67-
Note that some signal names have dashes in them, so to access them we rely on the backtick operator.
65+
The [COVIDcast
66+
endpoint](https://cmu-delphi.github.io/delphi-epidata/api/covidcast.html) of the
67+
Epidata API contains many separate data sources and signals. It can be difficult
68+
to find the name of the signal you're looking for, so you can use
69+
`covidcast_epidata` to get help with finding sources and functions without
70+
leaving R.
71+
72+
The `covidcast_epidata()` function fetches a list of all signals, and returns an
73+
object containing fields for every signal:
6874

6975
```{r}
70-
epidata <- epidatr:::covidcast_epidata()
76+
epidata <- covidcast_epidata()
7177
epidata$signals
78+
```
79+
80+
If you use an editor that supports tab completion, such as RStudio, type
81+
`epidata$signals$` and wait for the tab completion popup. You will be able to
82+
type the name of signals and have the autocomplete feature select them from the
83+
list for you. Note that some signal names have dashes in them, so to access them
84+
we rely on the backtick operator:
85+
86+
```{r}
7287
epidata$signals$`fb-survey:smoothed_cli`
7388
```
7489

75-
From there, you can construct a call analogous to the one above, but using the API object instead of the functions directly.
90+
These objects can be used directly to fetch data, without requiring us to use
91+
the `covidcast()` function. Simple use the `$call` attribute of the object:
7692

7793
```{r}
7894
epicall <- epidata$signals$`fb-survey:smoothed_cli`$call("state", "pa", epirange(20210405, 20210410))

0 commit comments

Comments
 (0)