Skip to content

Commit

Permalink
update documentation examples re #90
Browse files Browse the repository at this point in the history
  • Loading branch information
hrecht committed Mar 22, 2024
1 parent 889f32d commit fc0d589
Show file tree
Hide file tree
Showing 41 changed files with 927 additions and 763 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: A wrapper for the U.S. Census Bureau APIs that returns data frames
Small Area Income and Poverty Estimates, Population Estimates and Projections, and more.
URL: https://www.hrecht.com/censusapi/, https://github.com/hrecht/censusapi
BugReports: https://github.com/hrecht/censusapi/issues
Depends: R (>= 3.5.0)
Depends: R (>= 3.5)
License: GPL-3
LazyData: true
RoxygenNote: 7.3.1
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# censusapi 0.9.0
* The use of a Census Bureau API key (the `key` parameter) is no longer required with `getCensus()`. Users are still encouraged to register for and use an API key because the Census Bureau may rate limit IP addresses, but it is not required.
* `getCensus()` automatically converts data columns in the Household Pulse Survey to numeric.
* Increases required version of R from >=3.0 to >=3.5 based on httr dependency.
* A new online [frequently asked questions article](https://www.hrecht.com/censusapi/articles/frequently-asked-questions.html) improves documentation.
* Documentation is updated with new datasets, including more examples from the 2020 Decennial Census and the Household Pulse Survey.
* Documentation is updated to use newly released datasets.

# censusapi 0.8.0
* `listCensusApis()` has new columns in the resulting data frame of available API endpoints: the API `contact` email address and `type`: either Aggregate, Timeseries, or Microdata.
Expand Down
30 changes: 16 additions & 14 deletions R/getcensus_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ getFunction <- function(apiurl, name, key, get, region, regionin, time, year, da
#' @keywords api
#' @examples
#' \dontrun{
#' # Get total population and median household income for places (cities, towns, villages)
#' # in a single state from the 5-year ACS.
#' # Get total population and median household income for Census places
#' # (cities, towns, villages) in a single state from the 5-year American Community Survey.
#' acs_simple <- getCensus(
#' name = "acs/acs5",
#' vintage = 2022,
Expand All @@ -181,32 +181,34 @@ getFunction <- function(apiurl, name, key, get, region, regionin, time, year, da
#' # Retreive 2020 Decennial Census block group data within a specific Census tract,
#' # using the regionin argument to precisely specify the Census tract, county,
#' # and state.
#' block_group <- getCensus(
#' decennial_block_group <- getCensus(
#' name = "dec/dhc",
#' vintage = 2020,
#' vars = c("NAME", "P1_001N"),
#' region = "block group:*",
#' regionin = "state:36+county:027+tract:220300")
#' head(block_group)
#' head(decennial_block_group)
#'
#' # Get poverty rates for children and for people of all ages over time using the
#' # Get poverty rates for children and for people of all ages beginning in 2000 using the
#' # Small Area Income and Poverty Estimates API
#' saipe <- getCensus(
#' name = "timeseries/poverty/saipe",
#' vars = c("NAME", "SAEPOVRT0_17_PT", "SAEPOVRTALL_PT"),
#' region = "state:01",
#' time = "from 2000 to 2022")
#' time = "from 2000")
#' head(saipe)
#'
#' # Get County Business Patterns data for a specific NAICS sector.
#' cbp_2016 <- getCensus(
#' name = "cbp",
#' vintage = "2016",
#' vars = c("EMP", "ESTAB", "NAICS2012_TTL", "GEO_TTL"),
#' region = "state:*",
#' naics2012 = "23")
#' head(cbp_2016)
#' # Get the number of employees and number of establishments in the construction sector,
#' # NAICS2017 code 23, using the County Business Patterns API
#' cbp <- getCensus(
#' name = "cbp",
#' vintage = 2021,
#' vars = c("EMP", "ESTAB", "NAICS2017_LABEL"),
#' region = "county:*",
#' NAICS2017 = 23)
#' head(cbp)
#' }
#'
#' @export
getCensus <-
function(name,
Expand Down
72 changes: 38 additions & 34 deletions R/metadata_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,53 +58,57 @@ listCensusApis <- function() {
#' @keywords metadata
#' @examples
#' \dontrun{
#'
#' # type: variables
#' # List the variables available in the Small Area Health Insurance Estimates.
#' sahie_variables <- listCensusMetadata(
#' variables <- listCensusMetadata(
#' name = "timeseries/healthins/sahie",
#' type = "variables")
#' head(sahie_variables)
#' head(variables)
#'
#' # type: variables for a single variable group
#' # List the variables that are included in the B17020 group in the
#' # 5-year American Community Survey.
#' variable_group <- listCensusMetadata(
#' name = "acs/acs5",
#' vintage = 2022,
#' type = "variables",
#' group = "B17020")
#' head(variable_group)
#'
#' # List the geographies available in the 5-year 2020 American Community Survey.
#' acs_geographies <- listCensusMetadata(
#' # type: variables, with value labels
#' # Create a data dictionary with all variable names and encoded values for
#' # a microdata API.
#' variable_values <- listCensusMetadata(
#' name = "cps/voting/nov",
#' vintage = 2020,
#' type = "variables",
#' include_values = TRUE)
#' head(variable_values)
#'
#'# type: geographies
#' # List the geographies available in the 5-year American Community Survey.
#' geographies <- listCensusMetadata(
#' name = "acs/acs5",
#' vintage = 2020,
#' vintage = 2022,
#' type = "geographies")
#' head(acs_geographies)
#' head(geographies)
#'
#' # List the variable groups available in the 5-year 2020 American Community Survey.
#' acs_groups <- listCensusMetadata(
#' # type: groups
#' # List the variable groups available in the 5-year American Community Survey.
#' groups <- listCensusMetadata(
#' name = "acs/acs5",
#' vintage = 2020,
#' vintage = 2022,
#' type = "groups")
#' head(acs_groups)

#' # Create a data dictionary with all variable names and encoded values for
#' # a microdata API.
#' cbp_dict <- listCensusMetadata(
#' name = "cbp",
#' vintage = 2020,
#' type = "variables",
#' include_values = TRUE)
#' head(cbp_dict)
#' head(groups)
#'
#' # List the value labels of the NAICS2017 variable in the 2020 County
#' # Business Patterns dataset.
#' cbp_naics_values <- listCensusMetadata(
#' # type: values for a single variable
#' # List the value labels of the NAICS2017 variable in the County Business Patterns dataset.
#' naics_values <- listCensusMetadata(
#' name = "cbp",
#' vintage = 2020,
#' vintage = 2021,
#' type = "values",
#' variable = "NAICS2017")
#' head(cbp_naics_values)
#'
#' # List of variables that are included in the B17020 group in the
#' # 5-year American Community Survey.
#' group_B17020 <- listCensusMetadata(
#' name = "acs/acs5",
#' vintage = 2017,
#' type = "variables",
#' group = "B17020")
#' head(group_B17020)
#' head(naics_values)
#' }
#' @export
listCensusMetadata <-
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/CODE_OF_CONDUCT.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/accessing-microdata.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fc0d589

Please sign in to comment.