Skip to content

Commit

Permalink
Add filter_gisjoin function
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed May 21, 2024
1 parent 13a02b9 commit 05f0b12
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ Suggests:
sf,
tibble,
tidyr,
tigris,
tigris (>= 2.1.1),
withr
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Remotes:
elipousson/tigris
27 changes: 27 additions & 0 deletions R/filter_gisjoin.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#' Filter a NHGIS data frame by a state FIPS and county FIPS numbers
#'
#' By default, filter to counties in the Baltimore metro area.
#'
#' @param values Optional vector of GISJOIN values. state_fips and county_fips
#' are ignored if this is supplied.
#' @keywords internal
filter_gisjoin <- function(data,
state = NULL,
county = NULL,
values = NULL,
gisjoin_col = "GISJOIN") {
if (is.null(values)) {
check_installed("tigris")

if (!is.null(state) && is.null(county)) {
state <- tigris:::validate_state(state = state, multiple = TRUE)
values <- paste0("G", state_fips, "0")
} else {
state <- tigris:::validate_state(state = state)
county <- tigris:::validate_state(state = state, county = county, multiple = TRUE)
values <- paste0("G", state, "0", county, "0")
}
}

dplyr::filter(data, .data[[gisjoin_col]] %in% values)
}
22 changes: 22 additions & 0 deletions man/filter_gisjoin.Rd

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

0 comments on commit 05f0b12

Please sign in to comment.