Skip to content

Instantly share code, notes, and snippets.

@uribo
Created June 10, 2019 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uribo/40a0e67b9625062e816defabb88f8656 to your computer and use it in GitHub Desktop.
Save uribo/40a0e67b9625062e816defabb88f8656 to your computer and use it in GitHub Desktop.
subset_kanto_citycode <- function(data, city_code, .honsyu = TRUE) {
d <-
data %>%
# 関東 (一都六県) %>%
dplyr::filter(stringr::str_detect(!!rlang::enquo(city_code),
paste0("^(",
paste(stringr::str_pad(seq(8, 14), width = "2", pad = "0"), collapse = "|"),
")")))
if (rlang::is_true(.honsyu)) {
d <-
d %>%
# 本州のみ
dplyr::filter(stringr::str_detect(!!rlang::enquo(city_code), "^13", negate = TRUE) |
!!rlang::enquo(city_code) < 13361)
}
d
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment