Skip to content

Commit f2ad7e3

Browse files
committed
Remove PR excluded by default
1 parent 062e9af commit f2ad7e3

File tree

7 files changed

+30
-76
lines changed

7 files changed

+30
-76
lines changed

NEWS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
### New Features
44
* Puerto Rico has been added!
55
* Finally, after years of procrastinating, Puerto Rico has finally been added to the map, see [Issue #48](https://github.com/pdil/usmapdata/issues/48).
6-
* By default, it is not shown. It can be shown by setting `include = "PR"` (or using any combination of `include`/`exclude` parameters that results in `PR` being shown).
7-
* The default can be changed to show `PR` by setting the environment variable `USMAP_EXCLUDE_PR = FALSE`.
86
* All included map files have been retroactively updated to include Puerto Rico, so any valid value of `data_year` will include Puerto Rico if desired.
7+
* `us_map()` and `fips_data()` both return Puerto Rico in their data sets and it can be included or excluded just like any state (using FIPS, full name, abbreviation, etc.).
98
* Special thanks [@dcaud](https://github.com/dcaud) who started this work [years ago](https://github.com/pdil/usmap/pull/34).
109

1110
### Enhancements

R/aaa.R

Lines changed: 0 additions & 3 deletions
This file was deleted.

R/us-map.R

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@
1111
#' @param exclude The regions to exclude in the resulting map. If `regions` is
1212
#' `"states"`/`"state"`, the value can be either a state name, abbreviation or FIPS code.
1313
#' For counties, the FIPS must be provided as there can be multiple counties with the
14-
#' same name. The regions listed in the `include` parameter are applied first and the
15-
#' `exclude` regions are then removed from the resulting map. Any excluded regions
16-
#' not present in the included regions will be ignored. The default value is "PR".
17-
#' The default can be set to be an empty vector by setting the environment variable
18-
#' `USMAP_EXCLUDE_PR = FALSE`.
14+
#' same name. The regions listed in the `include` parameter take precedence over
15+
#' regions listed in `exclude`. If both parameters include the same region(s) they
16+
#' will be included in the map.
1917
#' @param data_year The year for which to obtain map data.
20-
#' If the value is `NULL`, the most recent year's data is used. If the
21-
#' provided year is not found from the available map data sets, the next most
22-
#' recent year's data is used. This can be used if an older data set is being
23-
#' plotted on the US map so that the data matches the map more accurately.
24-
#' Therefore, the provided value should match the year of the plotted data set.
25-
#' The default is `NULL`, i.e. the most recent available year is used.
18+
#' If the value is `NULL`, the most recent year's data is used. If the
19+
#' provided year is not found from the available map data sets, the next most
20+
#' recent year's data is used. This can be used if an older data set is being
21+
#' plotted on the US map so that the data matches the map more accurately.
22+
#' Therefore, the provided value should match the year of the plotted data set.
23+
#' The default is `NULL`, i.e. the most recent available year is used.
2624
#'
2725
#' @return An `sf` data frame of US map coordinates divided by the desired `regions`.
2826
#'
@@ -40,7 +38,7 @@
4038
us_map <- function(
4139
regions = c("states", "state", "counties", "county"),
4240
include = c(),
43-
exclude = .pkg_env$usmap_default_exclude(),
41+
exclude = c(),
4442
data_year = NULL
4543
) {
4644
regions <- match.arg(regions)
@@ -147,11 +145,3 @@ select_map_year <- function(data_year) {
147145
data_year
148146
}
149147
}
150-
151-
#' @keywords internal
152-
.pkg_env$usmap_default_exclude <- function() {
153-
if (Sys.getenv("USMAP_EXCLUDE_PR", unset = TRUE))
154-
c("PR")
155-
else
156-
c()
157-
}

man/dot-pkg_env.Rd

Lines changed: 0 additions & 16 deletions
This file was deleted.

man/us_map.Rd

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-fips-data.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ test_that("state FIPS codes load correctly", {
99
expect_identical(state_fips, states_fips)
1010

1111
expect_equal(length(fips), 3)
12-
expect_equal(length(fips[[1]]), 51)
12+
expect_equal(length(fips[[1]]), 52)
1313

1414
expect_equal(fips[[1, "abbr"]], "AK")
1515
expect_equal(fips[[1, "fips"]], "02")
1616
expect_equal(fips[[1, "full"]], "Alaska")
1717

18-
expect_equal(fips[[51, "abbr"]], "WY")
19-
expect_equal(fips[[51, "fips"]], "56")
20-
expect_equal(fips[[51, "full"]], "Wyoming")
18+
expect_equal(fips[[52, "abbr"]], "WY")
19+
expect_equal(fips[[52, "fips"]], "56")
20+
expect_equal(fips[[52, "full"]], "Wyoming")
2121
})
2222

2323
test_that("county FIPS codes load correctly", {
@@ -27,15 +27,15 @@ test_that("county FIPS codes load correctly", {
2727
expect_identical(county_fips, counties_fips)
2828

2929
expect_equal(length(county_fips), 4)
30-
expect_equal(length(county_fips[[1]]), 3144)
30+
expect_equal(length(county_fips[[1]]), 3222)
3131

3232
expect_equal(county_fips[[1, "full"]], "Alaska")
3333
expect_equal(county_fips[[1, "abbr"]], "AK")
3434
expect_equal(county_fips[[1, "county"]], "Aleutians East Borough")
3535
expect_equal(county_fips[[1, "fips"]], "02013")
3636

37-
expect_equal(county_fips[[3144, "full"]], "Wyoming")
38-
expect_equal(county_fips[[3144, "abbr"]], "WY")
39-
expect_equal(county_fips[[3144, "county"]], "Weston County")
40-
expect_equal(county_fips[[3144, "fips"]], "56045")
37+
expect_equal(county_fips[[3222, "full"]], "Wyoming")
38+
expect_equal(county_fips[[3222, "abbr"]], "WY")
39+
expect_equal(county_fips[[3222, "county"]], "Weston County")
40+
expect_equal(county_fips[[3222, "fips"]], "56045")
4141
})

tests/testthat/test-usmap.R

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,8 @@
22
states_map <- us_map(regions = "states")
33
counties_map <- us_map(regions = "counties")
44

5-
test_that("default us_map exclude is set", {
6-
withr::with_envvar(c("USMAP_EXCLUDE_PR" = NA), {
7-
expect_equal(usmapdata:::.pkg_env$usmap_default_exclude(), c("PR"))
8-
})
9-
10-
withr::with_envvar(c("USMAP_EXCLUDE_PR" = FALSE), {
11-
expect_equal(usmapdata:::.pkg_env$usmap_default_exclude(), c())
12-
})
13-
14-
withr::with_envvar(c("USMAP_EXCLUDE_PR" = TRUE), {
15-
expect_equal(usmapdata:::.pkg_env$usmap_default_exclude(), c("PR"))
16-
})
17-
})
18-
195
test_that("structure of states df is correct", {
20-
expect_equal(length(unique(states_map$fips)), 51)
6+
expect_equal(length(unique(states_map$fips)), 52)
217
})
228

239
test_that("correct states are included", {
@@ -66,7 +52,7 @@ test_that("include takes precedence over exclude", {
6652
})
6753

6854
test_that("structure of counties df is correct", {
69-
expect_equal(length(unique(counties_map$fips)), 3144)
55+
expect_equal(length(unique(counties_map$fips)), 3222)
7056
})
7157

7258
test_that("correct counties are included", {
@@ -97,10 +83,10 @@ test_that("error occurs for invalid region", {
9783
})
9884

9985
test_that("centroid labels are loaded", {
100-
expect_equal(length(centroid_labels("states")[[1]]), 51)
101-
expect_equal(length(centroid_labels("counties")[[1]]), 3144)
102-
expect_equal(length(centroid_labels("state")[[1]]), 51)
103-
expect_equal(length(centroid_labels("county")[[1]]), 3144)
86+
expect_equal(length(centroid_labels("states")[[1]]), 52)
87+
expect_equal(length(centroid_labels("counties")[[1]]), 3222)
88+
expect_equal(length(centroid_labels("state")[[1]]), 52)
89+
expect_equal(length(centroid_labels("county")[[1]]), 3222)
10490
expect_identical(centroid_labels("counties"), centroid_labels("county"))
10591
expect_identical(centroid_labels("states"), centroid_labels("state"))
10692
})

0 commit comments

Comments
 (0)