Skip to content

Commit

Permalink
add new get_api_key function, address #105
Browse files Browse the repository at this point in the history
  • Loading branch information
hrecht committed Apr 1, 2024
1 parent ee4a8b3 commit 25c8af9
Show file tree
Hide file tree
Showing 19 changed files with 707 additions and 948 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ LazyData: true
RoxygenNote: 7.3.1
Imports:
httr,
jsonlite
jsonlite,
rlang
Suggests:
knitr,
rmarkdown
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(getCensus)
export(getFunction)
export(get_api_key)
export(listCensusApis)
export(listCensusMetadata)
export(makeVarlist)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
## New features
* `getCensus()` no longer requires `key`, the use of a Census Bureau API key. 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. (#87)

* New `get_api_key()` helper function retrieves the value of a user's stored Census Bureau API key from a saved environment variable or provides a warning message if none is found.

* `listCensusApis()` now has optional `name` and `vintage` parameters to get metadata for a subset of datasets or a single dataset. (#103)

```R
Expand Down
8 changes: 1 addition & 7 deletions R/getcensus_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,7 @@ getCensus <-

# Check for key in environment, print a message if one is not provided or in environment
if (is.null(key)) {
if (Sys.getenv("CENSUS_KEY") != "") {
key <- Sys.getenv("CENSUS_KEY")
} else if (Sys.getenv("CENSUS_API_KEY") != "") {
key <- Sys.getenv("CENSUS_API_KEY")
} else {
message("You are not using a Census API key. Using a key is recommended but not required.\nThe Census Bureau may limit your daily requests.\nYou can register for an API key at https://api.census.gov/data/key_signup.html\nLearn more at https://www.hrecht.com/censusapi/articles/getting-started.html.")
}
key <- get_api_key()
}
apiurl <- constructURL(name, vintage)

Expand Down
15 changes: 9 additions & 6 deletions R/metadata_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ listCensusApis <- function(name = NULL,
#' @param name API programmatic name - e.g. acs/acs5. Use `listCensusApis()` to
#' see valid dataset names.
#' @param vintage Vintage (year) of dataset. Not required for timeseries APIs.
#' @param type Type of metadata to return. Options are: "variables" (default) -
#' list of variable names and descriptions for the dataset. "geographies" -
#' available geographies. "groups" - available variable groups. Only available
#' for some datasets. "values" - encoded value labels for a given variable.
#' Pair with "variable_name". This information is only available for some
#' datasets.
#' @param type Type of metadata to return. Options are:
#'
#' * "variables" (default) - list of variable names and descriptions
#' for the dataset.
#' * "geographies" - available geographies.
#' * "groups" - available variable groups. Only available
#' for some datasets.
#' * "values" - encoded value labels for a given variable. Pair with
#' "variable_name". Only available for some datasets.
#' @param group An optional variable group code, used to return metadata for a
#' specific group of variables only. Variable groups are not used for all
#' APIs.
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ reference:
- makeVarlist
- title: "Helpers"
contents:
- get_api_key
- fips

redirects:
Expand Down
Loading

0 comments on commit 25c8af9

Please sign in to comment.