Skip to content

Commit

Permalink
#88 conditionally apply standardisation
Browse files Browse the repository at this point in the history
- correctly apply `fns` in list-col using `pmap()` approach on entire dataframe, with support of wrapper / parser fun that parses the required variables to either `standardise_response()` or `process_response()`
- #97 delete comment
  • Loading branch information
egouldo committed Aug 14, 2024
1 parent 55ae434 commit e22ff1b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions R/prepare_response_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ prepare_response_variables <- function(ManyEcoEvo,
if (is.null(dataset_standardise)) {
out <- out %>%
ungroup() %>%
# dplyr::group_by(dataset) %>% #NOTE: mapping doesn't work properly when tibble is rowwise!
dplyr::mutate(data = purrr::map2(
.x = data,
.y = dataset,
Expand All @@ -92,12 +91,19 @@ prepare_response_variables <- function(ManyEcoEvo,
fns = list(standardise_response)
)

pmap_prepare_response <- function(data, estimate_type, param_table, dataset, fns, ...){
fns(data, estimate_type, param_table, dataset)
}

out <- out %>%
ungroup() %>%
left_join(datasets_to_standardise, by = "dataset") %>%
mutate(fns = coalesce(fns, list(process_response)),
data = map2(.x = data, .y = fns, ~ .y(.x))
)
data = pmap(.l = .,
.f = pmap_prepare_response,
estimate_type = estimate_type,
param_table = param_table)) %>%
select(-fns)
}
return(out)
}

0 comments on commit e22ff1b

Please sign in to comment.