Skip to content

Commit

Permalink
Merge pull request #21 from brendensm/master
Browse files Browse the repository at this point in the history
Updated XML defaults and edited vignettes
  • Loading branch information
jtr13 authored Feb 24, 2024
2 parents cdf6c99 + 6ecd5ee commit 032bc9e
Show file tree
Hide file tree
Showing 141 changed files with 1,275 additions and 1,675 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Authors@R: c(
role = c("cre", "aut")))
Description: Simplifies the process of formulating CDC Wonder API query
requests and interpreting query responses in order to obtain federal
health data
health data.
URL: https://github.com/socdataR/wonderapi
BugReports: https://github.com/socdataR/wonderapi/issues
Depends:
Expand All @@ -18,6 +18,7 @@ Imports:
magrittr,
purrr,
readr,
rlang,
rvest,
stats,
stringr,
Expand All @@ -33,4 +34,4 @@ VignetteBuilder: knitr
License: GPL
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
RoxygenNote: 7.3.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(dbnamelookup)
export(getBirths)
export(getData)
export(send_query)
Expand Down
1 change: 1 addition & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
#' ...
#' }
#' @source \code{data-raw/create_data_files.R}
#' @export dbnamelookup
"dbnamelookup"
8 changes: 4 additions & 4 deletions R/getBirths.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Request birth data from the CDC Wonder API
#'
#' wrapper to `getData()` which calls the \href{https://wonder.cdc.gov}{CDC Wonder API} and returns a tidy data frame (tibble)
#' NOT CURRENTLY IMPLEMENTED wrapper to `getData()` which calls the \href{https://wonder.cdc.gov}{CDC Wonder API} and returns a tidy data frame (tibble)
#'
#' @param ... list of words to indicate the group_by variables desired in the query. Words will be interpreted according to the first letter (not case-sensitive):
#'
Expand Down Expand Up @@ -38,9 +38,9 @@
#' mydata <- getBirths(age, educcation, wieght, gender)
#'
#' mydata
#'
#' @section Notes
#' `getBirths()` is designed to be easier to use than `getData()` for simple queries. For more options, use `getData()`.

#' @section Notes:
#' `getBirths()` is designed to be easier to use than `getData()` for simple queries. Only the first letter needs to be correct. For more options, use `getData()`.
#'

#' @export
Expand Down
6 changes: 3 additions & 3 deletions R/getData.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
#'
#' @examples
#' mylist <- list(
#' list("Group Results By", "Race"),
#' list("Tobacco Use", "1") # yes
#' list("And By", "Race"),
#' list("And By", "Tobacco Use")
#' )
#'
#' mydata <- getData("D66", mylist)
#' mydata
#'
#' @section References
#' @section References:
#' Inspired by this script from the \code{wondr} package, but provides more user-friendly options and better table display: /url{https://github.com/hrbrmstr/wondr/blob/master/README.md}
#'

Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion R/wonderapi-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' prepare data for either reports or further analysis.
#' @name wonderapi-package
#' @aliases wonderapi
#' @docType package
#' @docType _PACKAGE
#' @keywords package

NULL
Expand Down
56 changes: 24 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
**2023-01-31**
**Note: Much of the functionality of this package is not currently working, including obtaining natality data (D66). Calls to the mortality database (D76) appearing to be working, but have not been fully tested. If I haven't deterred you from trying, ignore the info below about building the vignettes and install with**


```
remotes::install_github("socdataR/wonderapi")
```

wonderapi
Introduction to wonderapi
================
Joyce Robbins
2022-03-24
2024-02-24

<div id="TOC">

Expand Down Expand Up @@ -79,11 +71,11 @@ write queries using human readable names rather than numeric codes.

`getData()`

- converts the user’s parameter requests to codes
- adds these codes to the default query list
- calls the WONDER API to obtain query results
- processes the results
- returns a tidy data frame
- converts the user’s parameter requests to codes
- adds these codes to the default query list
- calls the WONDER API to obtain query results
- processes the results
- returns a tidy data frame

## Limitations of the CDC WONDER API

Expand Down Expand Up @@ -126,8 +118,8 @@ wonderapi::show_databases()
## <chr> <chr>
## 1 Natality for 1995 - 2002 D10
## 2 Natality for 2003 - 2006 D27
## 3 Natality for 2007 - 2020 D66
## 4 Natality for 2016 - 2020 (expanded) D149
## 3 Natality for 2007 - 2022 D66
## 4 Natality for 2016 - 2022 (expanded) D149
## 5 Detailed Mortality D76
## 6 Provisional Multiple Cause of Death D176
## 7 Heat Wave Days D104
Expand Down Expand Up @@ -213,7 +205,7 @@ default settings, perform a query request without specifying a
querylist:

``` r
natdata <- getData("Natality for 2007 - 2020")
natdata <- getData("Natality for 2007 - 2022")
natdata %>% head()
```

Expand Down Expand Up @@ -313,7 +305,7 @@ Measures do not need values; it is sufficient to specify a name only:
mylist <- list(list("Group Results By", "Marital Status"),
list("And By", "Year"),
list("Average Age of Mother", ""))
mydata2 <- getData("Natality for 2007 - 2020", mylist)
mydata2 <- getData("Natality for 2007 - 2022", mylist)
```

``` r
Expand Down Expand Up @@ -342,7 +334,7 @@ mylist <- list(list("Month", "2"))
getData("D66", mylist)
```

## # A tibble: 14 × 2
## # A tibble: 16 × 2
## Year Births
## <dbl> <dbl>
## 1 2007 326891
Expand All @@ -359,6 +351,8 @@ getData("D66", mylist)
## 12 2018 284250
## 13 2019 279963
## 14 2020 282654
## 15 2021 266355
## 16 2022 275727

**Note that values for Limiting Variables must be entered as codes; in
this case “2” rather than “February.” We hope to add capability for
Expand All @@ -374,7 +368,7 @@ ggplot(mydata2, aes(x = Year, y = Births, color = `Marital Status`)) +
geom_line() + ggtitle("Births by Marital Status")
```

<img src="man/figures/BirthsByMaritalStatus-1.png" style="display: block; margin: auto;" />
<img src="readme_files/figure-gfm/BirthsByMaritalStatus-1.png" style="display: block; margin: auto;" />

``` r
ggplot(mydata2, aes(x = Year, y = `Average Age of Mother`,
Expand All @@ -383,7 +377,7 @@ ggplot(mydata2, aes(x = Year, y = `Average Age of Mother`,
ggtitle("Average Age of Mother")
```

<img src="man/figures/AverageAgeofMother-1.png" style="display: block; margin: auto;" />
<img src="readme_files/figure-gfm/AverageAgeofMother-1.png" style="display: block; margin: auto;" />

``` r
mydata2 <- mydata2 %>%
Expand All @@ -395,7 +389,7 @@ ggplot(mydata2, aes(x = Year, y = Unmarried / Total)) + geom_line() +
ylab("Percent of Total Births")
```

<img src="man/figures/BirthstoUnmarriedMothers-1.png" style="display: block; margin: auto;" />
<img src="readme_files/figure-gfm/BirthstoUnmarriedMothers-1.png" style="display: block; margin: auto;" />

### Combining results from multiple datasets

Expand All @@ -410,12 +404,12 @@ available, see the codebooks (**`>??codebook`**) and crosscheck with the
``` r
births <- rbind(getData("Natality for 1995 - 2002"),
getData("Natality for 2003 - 2006"),
getData("Natality for 2007 - 2020"))
getData("Natality for 2007 - 2022"))
ggplot(births, aes(Year, Births)) + geom_line() +
ggtitle("U.S. Births by Year, 1995 - 2020")
ggtitle("U.S. Births by Year, 1995 - 2022")
```

<img src="man/figures/BirthsbyYear1995to2020-1.png" style="display: block; margin: auto;" />
<img src="readme_files/figure-gfm/BirthsbyYear-1.png" style="display: block; margin: auto;" />

### Errors

Expand All @@ -433,7 +427,7 @@ mydata3 <- getData("Detailed Mortality",
list(list("Suspect", "Mrs. Peacock")))
```

## Ignoring: "Suspect",...(not recognized)
## Couldn't find: "Suspect" but including anyway.

``` r
mydata3 %>% head()
Expand All @@ -456,15 +450,13 @@ fix the problem. Other times, it is not. For example:
``` r
mylist <- list(list("And By", "Education"),
list("Birth Rate", ""))
mydata4 <- getData("Natality for 2007 - 2020", mylist)
mydata4 <- getData("Natality for 2007 - 2022", mylist)
```

## No encoding supplied: defaulting to UTF-8.

## Message from query:
## Any by-variables picked from {0} need to appear in the order listed, and other by-variables can't come between them.

## Error in getData("Natality for 2007 - 2020", mylist): Internal Server Error (HTTP 500).
## Error in getData("Natality for 2007 - 2022", mylist): Internal Server Error (HTTP 500).

In this case, the best approach is to visit the [CDC Wonder API web
interface](https://wonder.cdc.gov) and try the same query. If all goes
Expand All @@ -481,7 +473,7 @@ Rate” measure. If we try again with “Bridged Race” instead of
``` r
mylist <- list(list("And By", "Mother's Bridged Race"),
list("Birth Rate", ""))
mydata5 <- getData("Natality for 2007 - 2020", mylist)
mydata5 <- getData("Natality for 2007 - 2022", mylist)
```

``` r
Expand Down
15 changes: 14 additions & 1 deletion data-raw/D10_Defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
</parameter>
<parameter>
<name>O_title</name>
<value>Births 1995-2002 by year </value>
<value/>
</parameter>
<parameter>
<name>V_D10.V1</name>
Expand Down Expand Up @@ -187,6 +187,19 @@
<name>action-Send</name>
<value>Send</value>
</parameter>
<parameter>
<name>dataset_code</name>
<value>D10</value>
</parameter>
<parameter>
<name>dataset_label</name>
<value>Natality, 1995-2002</value>
</parameter>
<parameter>
<name>dataset_vintage</name>
<value>Pre Expansion</value>
</parameter>

<parameter>
<name>finder-stage-D10.V21</name>
<value>codeset</value>
Expand Down
22 changes: 7 additions & 15 deletions data-raw/D149_Defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@
<name>O_frace</name>
<value>D149.V54</value>
</parameter>
<parameter>
<name>O_gain</name>
<value>D149.V72</value>
</parameter>
<parameter>
<name>O_gestation</name>
<value>D149.V23</value>
Expand Down Expand Up @@ -163,13 +159,17 @@
<name>O_rate_per</name>
<value>1000</value>
</parameter>
<parameter>
<name>O_show_totals</name>
<value>true</value>
</parameter>
<parameter>
<name>O_timeout</name>
<value>600</value>
</parameter>
<parameter>
<name>O_title</name>
<value></value>
<value/>
</parameter>
<parameter>
<name>O_urban</name>
Expand Down Expand Up @@ -511,10 +511,6 @@
<name>V_D149.V4</name>
<value>*All*</value>
</parameter>
<parameter>
<name>V_D149.V40</name>
<value>*All*</value>
</parameter>
<parameter>
<name>V_D149.V41</name>
<value>*All*</value>
Expand Down Expand Up @@ -639,10 +635,6 @@
<name>V_D149.V71</name>
<value>*All*</value>
</parameter>
<parameter>
<name>V_D149.V72</name>
<value>*All*</value>
</parameter>
<parameter>
<name>V_D149.V73</name>
<value>*All*</value>
Expand Down Expand Up @@ -769,11 +761,11 @@
</parameter>
<parameter>
<name>dataset_label</name>
<value>Natality, 2016-2019 expanded</value>
<value>Natality, 2016-2022 expanded</value>
</parameter>
<parameter>
<name>dataset_vintage</name>
<value>2019</value>
<value>2022</value>
</parameter>
<parameter>
<name>finder-stage-D149.V21</name>
Expand Down
15 changes: 7 additions & 8 deletions data-raw/D27_Defaults.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<request-parameters>
<?xml version='1.0' encoding='utf-8'?><request-parameters>
<parameter>
<name>accept_datause_restrictions</name>
<value>true</value>
Expand Down Expand Up @@ -105,7 +104,7 @@
</parameter>
<parameter>
<name>O_title</name>
<value>Births 2003-2006 by year, all measures checked </value>
<value/>
</parameter>
<parameter>
<name>O_weight</name>
Expand Down Expand Up @@ -169,7 +168,7 @@
</parameter>
<parameter>
<name>V_D27.V22</name>
<value></value>
<value/>
</parameter>
<parameter>
<name>V_D27.V23</name>
Expand Down Expand Up @@ -217,7 +216,7 @@
</parameter>
<parameter>
<name>V_D27.V37</name>
<value></value>
<value/>
</parameter>
<parameter>
<name>V_D27.V38</name>
Expand All @@ -232,11 +231,11 @@
<value>*All*</value>
</parameter>
<parameter>
<name>V_D27.V40</name>
<name>V_D27.V41</name>
<value>*All*</value>
</parameter>
<parameter>
<name>V_D27.V41</name>
<name>V_D27.V43</name>
<value>*All*</value>
</parameter>
<parameter>
Expand Down Expand Up @@ -289,7 +288,7 @@
</parameter>
<parameter>
<name>saved_id</name>
<value></value>
<value/>
</parameter>
<parameter>
<name>stage</name>
Expand Down
Loading

0 comments on commit 032bc9e

Please sign in to comment.