Skip to content

Commit

Permalink
#88 add argument for selectively standardising
Browse files Browse the repository at this point in the history
- NOTE: dummy function for datasets not selected for standardising is currently applied
- TODO: update dummy function
- TODO: apply functions with map2
  • Loading branch information
egouldo committed Aug 14, 2024
1 parent bb68fa4 commit a75be28
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
57 changes: 39 additions & 18 deletions R/prepare_response_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
#' @export
prepare_response_variables <- function(ManyEcoEvo,
estimate_type = character(1L),
param_table = NULL) {
param_table = NULL,
dataset_standardise = NULL) {

stopifnot(is.data.frame(ManyEcoEvo))
# TODO run checks on ManyEcoEvo
match.arg(estimate_type, choices = c("Zr", "yi", "y25", "y50", "y75"), several.ok = FALSE)
# TODO insert check that non-All dataset_standardise is a valid dataset name, i.e.
# present in ManyEcoEvo$dataset

out <- ManyEcoEvo

Expand Down Expand Up @@ -48,29 +52,46 @@ prepare_response_variables <- function(ManyEcoEvo,
distinct()
)
)

} else{
} else{
if (!is.null(param_table)) {
cli::cli_abort("{.arg param_table} must be NULL for {.val {estimate_type}} data")
}
}

# ------ Standardise Response Variables for Meta-analysis ------
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,
.f = ~ standardise_response(
dat = .x,
estimate_type = !!{
estimate_type
},
param_table,
dataset = .y
)
))

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,
.f = ~ standardise_response(
dat = .x,
estimate_type = !!{
estimate_type
},
param_table,
dataset = .y
)
))
} else {

process_response <- function(dat){
dat #TODO replace dummy function with actual function
}

out <- out %>%
ungroup() %>%
mutate(fns = map(dataset,
~ case_match(.x,
!!{dataset_standardise} ~ "standardise_response",
.default = "process_response") %>%
rlang::as_function()))

}

return(out)

Expand Down
2 changes: 1 addition & 1 deletion _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ list(tarchetypes::tar_file_read(name = euc_reviews,
"constructed",
negate = TRUE)))) %>%
prepare_response_variables(estimate_type = "yi",
param_table = ManyEcoEvo:::analysis_data_param_tables) %>%
param_table = ManyEcoEvo:::analysis_data_param_tables,dataset_standardise = "blue tit") %>%
generate_yi_subsets() %>% #TODO: must be run after prepare_response_variables??
apply_VZ_exclusions(3) %>%
generate_exclusion_subsets() %>% #TODO: runs on ManyEcoEvo that contains Zr and yi results.
Expand Down

0 comments on commit a75be28

Please sign in to comment.