Skip to content

Commit

Permalink
bug!: bug-fixes after testing #118 on yi pipeline
Browse files Browse the repository at this point in the history
- add import tag for `purrr::transpose()` in `fit_multivar_MA()` #102
- defuse argument `outcome` in `cli()` call in `fit_boxcox_ratings_cont()`

- `meta_analyse_datasets()`:
  - use correct argument in calls to `fit_boxcox_ratings_*()` (`data` from `.data`)
  - apply coalesce on list-cols only and `@import` `tidyselect::where()` (previously non-list-cols were ignored because character columns were explicitly grouped, however current approach in pipeline is ungrouped in order to allow for generalisability / scalability #87. Can't caoalesce a character vector and list, must be of same type).

build!: update calls in targets `yi` pipeline
  • Loading branch information
egouldo committed Aug 28, 2024
1 parent 4b228cb commit 25418a1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 29 deletions.
30 changes: 19 additions & 11 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,14 @@ export(summarise_variable_counts)
export(validate_predictions)
export(validate_predictions_df_blue_tit)
export(variance_box_cox)
import(NatParksPalettes)
import(broom)
import(broom.mixed)
import(cli)
import(dplyr)
import(forcats)
import(ggforestplot)
import(ggplot2)
import(lme4)
import(metafor)
import(purrr)
import(rlang)
import(see)
import(stringr)
import(tidyr)
importFrom(EnvStats,stat_n_text)
importFrom(NatParksPalettes,scale_color_natparks_d)
importFrom(betapart,beta.pair)
importFrom(broom,tidy)
importFrom(broom.mixed,tidy)
importFrom(cli,cli_abort)
importFrom(cli,cli_alert)
Expand Down Expand Up @@ -191,12 +182,14 @@ importFrom(purrr,exec)
importFrom(purrr,flatten_dbl)
importFrom(purrr,is_scalar_vector)
importFrom(purrr,keep)
importFrom(purrr,keep_at)
importFrom(purrr,list_c)
importFrom(purrr,list_flatten)
importFrom(purrr,list_rbind)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map_chr)
importFrom(purrr,map_dfr)
importFrom(purrr,map_if)
importFrom(purrr,map_int)
importFrom(purrr,map_lgl)
Expand All @@ -206,6 +199,8 @@ importFrom(purrr,possibly)
importFrom(purrr,reduce)
importFrom(purrr,reduce2)
importFrom(purrr,set_names)
importFrom(purrr,simplify)
importFrom(purrr,transpose)
importFrom(readr,read_csv)
importFrom(recipes,juice)
importFrom(recipes,prep)
Expand All @@ -214,18 +209,27 @@ importFrom(recipes,step_mutate)
importFrom(recipes,step_naomit)
importFrom(recipes,tidy)
importFrom(recipes,update_role)
importFrom(rlang,"!!")
importFrom(rlang,":=")
importFrom(rlang,as_function)
importFrom(rlang,as_string)
importFrom(rlang,caller_env)
importFrom(rlang,enquo)
importFrom(rlang,ensym)
importFrom(rlang,exec)
importFrom(rlang,expr)
importFrom(rlang,exprs)
importFrom(rlang,f_lhs)
importFrom(rlang,inject)
importFrom(rlang,is_call)
importFrom(rlang,is_list)
importFrom(rlang,is_na)
importFrom(rlang,is_null)
importFrom(rlang,na_chr)
importFrom(rlang,new_formula)
importFrom(sae,bxcx)
importFrom(see,geom_jitter2)
importFrom(see,scale_fill_material_d)
importFrom(see,theme_modern)
importFrom(stringr,str_detect)
importFrom(stringr,str_remove)
Expand All @@ -237,14 +241,18 @@ importFrom(tibble,enframe)
importFrom(tibble,rownames_to_column)
importFrom(tibble,tibble)
importFrom(tidyr,any_of)
importFrom(tidyr,drop_na)
importFrom(tidyr,hoist)
importFrom(tidyr,nest)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,separate)
importFrom(tidyr,tibble)
importFrom(tidyr,unite)
importFrom(tidyr,unnest)
importFrom(tidyr,unnest_longer)
importFrom(tidyselect,all_of)
importFrom(tidyselect,where)
importFrom(timetk,step_box_cox)
importFrom(workflows,add_model)
importFrom(workflows,add_recipe)
Expand Down
2 changes: 1 addition & 1 deletion R/filt_multivar_MA.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @importFrom lme4 lmer
#' @importFrom pointblank test_col_vals_gte expect_col_exists
#' @import dplyr
#' @importFrom purrr list_flatten list_c
#' @importFrom purrr list_flatten list_c transpose
#' @importFrom tibble enframe
#' @importFrom tidyr unite
#' @importFrom cli cli_alert_info cli_bullets cli_h2 style_italic
Expand Down
2 changes: 1 addition & 1 deletion R/fit_boxcox_ratings_cat.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fit_boxcox_ratings_cat <- function(data, outcome, outcome_var, interceptless = F
)

# ----- Fit model -----
cli::cli_h2(c("Fitting {.fn lmer} with categorical ratings predictor {.arg PublishableAsIs} on Box-Cox transformed outcome: outcome: {.val {outcome}}"))
cli::cli_h2(c("Fitting {.fn lmer} with categorical ratings predictor {.arg PublishableAsIs} on Box-Cox transformed {.arg outcome}: {.arg {rlang::enexpr(outcome)}}"))

data_tbl <-
data %>%
Expand Down
2 changes: 1 addition & 1 deletion R/fit_boxcox_ratings_cont.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fit_boxcox_ratings_cont <- function(data, outcome, outcome_var, ..., env = rlang
)

# ----- Fit model -----
cli::cli_h2(c("Fitting {.fn lmer} with continuous ratings predictor {.arg RateAnalysis} on Box-Cox transformed outcome: {.val {outcome}}"))
cli::cli_h2(c("Fitting {.fn lmer} with continuous ratings predictor {.arg RateAnalysis} on Box-Cox transformed {.arg outcome}: {.arg {rlang::enexpr(outcome)}}"))
data_tbl <- # TODO, consider extracting unnesting outside of this fn.
data %>%
select(
Expand Down
14 changes: 8 additions & 6 deletions R/meta_analyse_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#' @importFrom stringr str_detect
#' @importFrom purrr map_chr map2 map possibly pmap list_c map_lgl
#' @import dplyr
#' @importFrom tidyselect where
#' @importFrom cli cli_h1 cli_abort
#' @importFrom rlang na_chr is_null na_chr is_list is_call exprs f_lhs as_string
#' @importFrom pointblank expect_col_exists
Expand Down Expand Up @@ -197,7 +198,7 @@ meta_analyse_datasets <- function(data, outcome_variable = NULL, outcome_SE = NU
purrr::map(
.x = effects_analysis,
.f = ~ fit_boxcox_ratings_cont(
.data = .x,
data = .x,
outcome = box_cox_abs_deviation_score_estimate,
outcome_var = box_cox_var
)
Expand All @@ -206,7 +207,7 @@ meta_analyse_datasets <- function(data, outcome_variable = NULL, outcome_SE = NU
purrr::map(
.x = effects_analysis,
.f = ~ poss_fit_boxcox_ratings_cat(
.data = .x,
data = .x,
outcome = box_cox_abs_deviation_score_estimate,
outcome_var = box_cox_var,
interceptless = FALSE
Expand All @@ -216,7 +217,7 @@ meta_analyse_datasets <- function(data, outcome_variable = NULL, outcome_SE = NU
purrr::map(
.x = effects_analysis,
.f = ~ poss_fit_boxcox_ratings_cat(
.data = .x,
data = .x,
outcome = box_cox_abs_deviation_score_estimate,
outcome_var = box_cox_var,
interceptless = TRUE
Expand Down Expand Up @@ -268,9 +269,10 @@ meta_analyse_datasets <- function(data, outcome_variable = NULL, outcome_SE = NU

out <-
out %>% # replace any NULL values with NA
mutate(across(everything(),
.fns = ~ coalesce(.x, list(NA))
))
mutate(
across(where(is.list),
.fns = ~ coalesce(.x, list(NA)))
)

return(out)
}
27 changes: 18 additions & 9 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,27 @@ list(tarchetypes::tar_file_read(name = euc_reviews,
dataset_log_transform = "eucalyptus") %>%
generate_yi_subsets() %>% #TODO: must be run after prepare_response_variables??
apply_VZ_exclusions(
VZ_colname = list("eucalyptus" = "std.error_log",
VZ_colname = list("eucalyptus" = "se_log",
"blue tit" = "VZ"),
VZ_cutoff = 3) %>%
generate_exclusion_subsets() %>% #TODO: runs on ManyEcoEvo that contains Zr and yi results.
generate_outlier_subsets(outcome_variable =
list(dataset = list("eucalyptus" = "mean_log",
"blue tit" = "Z")),
n_min = -3,
n_max = -3,
ignore_subsets = NULL) %>%
generate_exclusion_subsets() %>% #TODO: runs on ManyEcoEvo that contains Zr and yi results; DELETE, not needed
generate_outlier_subsets(
outcome_variable =
list(dataset =
list("eucalyptus" = "mean_log",
"blue tit" = "Z")),
n_min = -3,
n_max = -3,
ignore_subsets = NULL) %>%
compute_MA_inputs() %>%
meta_analyse_datasets(filter_vars = NULL) #TODO requires col exclusion_set from generate_exclusion_subsets() but don't need that fun in this pipeline anymore
meta_analyse_datasets(
outcome_variable =
list(dataset =
list("eucalyptus" = "mean_log", "blue tit" = "Z")),
outcome_SE =
list(dataset =
list("eucalyptus" = "se_log", "blue tit" = "VZ")),
filter_vars = rlang::exprs(exclusion_set == "complete")) #TODO requires col exclusion_set from generate_exclusion_subsets() but don't need that fun in this pipeline anymore
),
targets::tar_target(name = ManyEcoEvo_yi_viz,
command = make_viz(ManyEcoEvo_yi_results)),
Expand Down

0 comments on commit 25418a1

Please sign in to comment.