calls the CDC Wonder API and returns a tidy data frame (tibble)
Usage
getData(
db = "D66",
querylist = NULL,
add = TRUE,
save = FALSE,
fn = "query.xml",
agree = TRUE
)
Arguments
- db
Indicate the database, either by label, name, or code. To see the complete list of what's available, use `show_databases()`
- querylist
The query list supplied must be a list of lists of names and values. By default it is combined with the default query list for that database. To supply a full list and bypass the default query list, set
add
toTRUE
. See here for instructions on how to create this list.- add
If
TRUE
(default)querylist
is combined with the default query list. Set toFALSE
to usequerylist
as a standalone list of query parameters.- save
If
TRUE
the query list will be saved, defaults toFALSE
- fn
filename for saved query list, defaults to
query.xml
.- agree
Must be set to TRUE to agree to the CDC terms (default is TRUE). To see the terms for the particular dataset click on that dataset here: https://wonder.cdc.gov. sample
Details
Queries for mortality and births statistics from the National Vital Statistics System cannot limit or group results by any location field, such as Region, Division, State or County, or Urbanization (urbanization categories map to specific geographic counties).
For example, in the D76 online database for Detailed Mortality 1999-2013, the location fields are D76.V9, D76.V10 and D76.V27, and the urbanization fields are D76.V11 and D76.V19. These 'sub-national" data fields cannot be grouped by or limited via the API, although these fields are available in the web application.
See https://wonder.cdc.gov/wonder/help/WONDER-API.html for more information.
References
Inspired by this script from the wondr
package, but provides more user-friendly options and better table display: /urlhttps://github.com/hrbrmstr/wondr/blob/master/README.md
Examples
mylist <- list(
list("And By", "Race"),
list("And By", "Tobacco Use")
)
mydata <- getData("D66", mylist)
mydata
#> # A tibble: 57 × 3
#> Year `Tobacco Use` Births
#> <dbl> <chr> <dbl>
#> 1 2007 Yes 210242
#> 2 2007 No 1805676
#> 3 2007 Unknown or Not Stated 45131
#> 4 2007 Not Reported 2255184
#> 5 2008 Yes 215546
#> 6 2008 No 1997233
#> 7 2008 Unknown or Not Stated 36348
#> 8 2008 Not Reported 1998567
#> 9 2009 Yes 206895
#> 10 2009 No 2007871
#> # ℹ 47 more rows