Skip to content

Commit

Permalink
more minor tweaks to read_erp
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCowgill committed Jan 14, 2025
1 parent 8f6d9e8 commit 85bef67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 12 additions & 11 deletions R/read_erp.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,20 @@ read_erp <- function(age_range = 0:100,

x <- erp_raw %>%
dplyr::mutate(
age = gsub("[^0-9]", "", series),
age = as.integer(age),
series_sex = gsub(".*;\\s*(Male|Female|Persons)\\s*;.*", "\\1", series),
state = trimws(gsub(".*,(\\s*[^,]+)$", "\\1", table_title))
age = gsub("[^0-9]", "", .data$series),
age = as.integer(.data$age),
series_sex = gsub(".*;\\s*(Male|Female|Persons)\\s*;.*", "\\1", .data$series),
state = trimws(gsub(".*,(\\s*[^,]+)$", "\\1", .data$table_title))
) %>%
dplyr::filter(
age %in% age_range,
series_sex %in% sex
.data$age %in% age_range,
.data$series_sex %in% sex
) %>%
dplyr::group_by(date, series_sex, state, age) %>%
dplyr::summarise(erp = sum(value)) %>%
dplyr::arrange(state, series_sex, age, date) %>%
dplyr::select(date, state, sex = series_sex, erp, age)
dplyr::group_by(.data$date, .data$series_sex, .data$state, .data$age) %>%
dplyr::summarise(erp = sum(.data$value)) %>%
dplyr::arrange(.data$state, .data$series_sex, .data$age, .data$date) %>%
dplyr::select("date", "state", sex = "series_sex",
"erp", "age")

x
}
Expand Down Expand Up @@ -159,7 +160,7 @@ validate_state <- function(state) {
tolower(valid_abbreviations))

# Create a lookup table (map all variants to full state names)
state_map <- setNames(
state_map <- stats::setNames(
rep(valid_states, times = 5),
all_valid_inputs
)
Expand Down
4 changes: 2 additions & 2 deletions man/read_erp.Rd

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

0 comments on commit 85bef67

Please sign in to comment.