Skip to content

Commit

Permalink
expand_types(): speed up the grouped case
Browse files Browse the repository at this point in the history
  • Loading branch information
florisvdh committed Jan 24, 2024
1 parent d08bfa0 commit 13d05ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
38 changes: 22 additions & 16 deletions R/datawrangling.R
Expand Up @@ -130,11 +130,26 @@ expand_types <- function(x,
assert_that(is.flag(use_grouping), noNA(use_grouping))
assert_that(is.flag(strict), noNA(strict))

types <-
read_types() %>%
select(1:3)

subtypes <-
types %>%
filter(.data$typelevel == "subtype") %>%
select(1, 3)

if (!all(unique(x[[type_var]]) %in% types$type)) {
warning("The data frame contains type codes which are not standard.")
}

if (!use_grouping) {
expand_types_plain(
x = x,
type_var = type_var,
strict = strict
strict = strict,
types = types,
subtypes = subtypes
)
} else {
x %>%
Expand All @@ -143,7 +158,9 @@ expand_types <- function(x,
mutate(newdata = map(.data$data,
expand_types_plain,
type_var = type_var,
strict = strict
strict = strict,
types = types,
subtypes = subtypes
)) %>%
select(-.data$data) %>%
unnest(cols = .data$newdata) %>%
Expand Down Expand Up @@ -186,24 +203,13 @@ expand_types <- function(x,
#' @keywords internal
expand_types_plain <- function(x,
type_var = "type",
strict = TRUE) {
types <-
read_types() %>%
select(1:3)

subtypes <-
types %>%
filter(.data$typelevel == "subtype") %>%
select(1, 3)

strict = TRUE,
types,
subtypes) {
orig_types <-
x[, type_var] %>%
rename(orig_abcd = type_var)

if (!all(unique(orig_types$orig_abcd) %in% types$type)) {
warning("The data frame contains type codes which are not standard.")
}

# main types to add:
suppressWarnings(
join_main_types <-
Expand Down
2 changes: 1 addition & 1 deletion man/expand_types_plain.Rd

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

0 comments on commit 13d05ec

Please sign in to comment.