Skip to content

Commit

Permalink
Fix fips data calls and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pdil committed Dec 11, 2023
1 parent 4b5a66f commit d35de14
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 34 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ URL: https://usmap.dev
BugReports: https://github.com/pdil/usmap/issues
Imports:
rlang,
usmapdata,
utils
usmapdata (>= 0.1.2)
Suggests:
covr,
ggplot2,
Expand Down
14 changes: 12 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# usmap 0.6.3.9999

### Improvements
* Replace local state and county FIPS files with `usmapdata::fips_data()`.
* Single source of truth for this data is now housed in `usmapdata`.
* Data will be updated in sync with shapefile updates.

### Bug Fixes
* FIPS file change resolves issue with Valdez-Cordova Census Area in Alaska, see [Issue #72](https://github.com/pdil/usmap/issues/72).

### Technical Changes
* Resolve all code-linting warnings.
* Increase test coverage to 100%.

# usmap 0.6.3
Released Saturday, October 21, 2023.
Expand Down Expand Up @@ -36,7 +46,7 @@ Released Sunday, February 27, 2022.
* Extract map data frame to external [usmapdata](https://github.com/pdil/usmapdata) package to reduce `usmap` package size, see [Issue #39](https://github.com/pdil/usmap/issues/39).
* All existing functions (including `us_map()`) should continue to work as usual.
* Add data format examples for `plot_usmap` to "Mapping" vignette, see [Issue #42](https://github.com/pdil/usmap/issues/42).

### Bug Fixes
* Fix CRS warnings, see [Issue #40](https://github.com/pdil/usmap/issues/40).
* Fix `plot_usmap()` issue when provided data has `"values"` column, see [Issue #48](https://github.com/pdil/usmap/issues/48) and [this Stack Overflow question](https://stackoverflow.com/questions/61111024/trouble-using-plot-usmap-function-in-usmap-package).
Expand Down Expand Up @@ -71,7 +81,7 @@ Released Friday, September 13, 2019.
* Ability to exclude counties and states with new `exclude` parameter in `us_map`, `map_with_data`, and `plot_usmap`, see [Issue #19](https://github.com/pdil/usmap/issues/19).
* New function (`usmap_transform`) to transform longitude/latitude point data frames into coordinate reference system that matches the plotted map, see [Issue #21](https://github.com/pdil/usmap/issues/21).
* Also includes `usmap_crs()` to easily access the coordinate reference system used by the package.

### Improvements
* In the data frames provided by `us_map()`, `long` and `lat` have been renamed to `x` and `y`, respectively, see [Issue #16](https://github.com/pdil/usmap/issues/16).
* This should not affect the behavior of `plot_usmap()` but will be a breaking change for any code that relies on `us_map()`.
Expand Down
11 changes: 4 additions & 7 deletions R/fips.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
#' @export
fips <- function(state, county = c()) {
if (missing(state) && missing(county)) {
df <- usmapdata::fips_data()
return(sprintf("%02d", df$fips))
return(usmapdata::fips_data()$fips)
}

state_ <- tolower(state)
Expand All @@ -66,10 +65,8 @@ fips <- function(state, county = c()) {
fips2 <- c(df$fips, df$fips)

result <- fips2[match(state_, c(abbr, full))]

formatted_result <- sprintf("%02d", result)
formatted_result[formatted_result == "NA"] <- NA
formatted_result
result[result == "NA"] <- NA
result
} else {
if (length(state_) > 1) {
stop("`county` parameter cannot be used with multiple states.")
Expand Down Expand Up @@ -99,7 +96,7 @@ fips <- function(state, county = c()) {
stop(paste0(county, " are not valid counties in ", state, ".\n"))
}
} else {
sprintf("%05d", result)
result
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions man/set_sp_evolution_status.Rd

This file was deleted.

6 changes: 0 additions & 6 deletions tests/testthat/test-transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,3 @@ test_that("error occurs for data with non-numeric columns", {
expect_error(usmap_transform(invalid_data2))
expect_error(usmap_transform(invalid_data3))
})

test_that("sp evolution status is set correctly", {
sp::set_evolution_status(1L)
usmap_transform(data.frame(lon = 0, lat = 0))
expect_equal(sp::get_evolution_status(), 2L)
})

0 comments on commit d35de14

Please sign in to comment.