Skip to content

Commit

Permalink
Enhance code for set_config_cpm()
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zhang <psychelzh@outlook.com>
  • Loading branch information
psychelzh committed Jan 26, 2024
1 parent d120be0 commit e95d57f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 4 additions & 5 deletions R/tar_factories.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ tar_fit_cfa <- function(config, data, theory,
)
}

tar_prep_files_cpm <- function(params_subset = NULL) {
values <- config_files({{ params_subset }})
tar_prep_files_cpm <- function(...) {
values <- set_config_cpm(...)
c(
tarchetypes::tar_eval(
tar_target(
Expand Down Expand Up @@ -368,14 +368,13 @@ tar_prep_files_cpm <- function(params_subset = NULL) {
}

# helper functions ----
config_files <- function(params_subset = NULL) {
if (rlang::quo_is_null(rlang::enquo(params_subset))) params_subset <- TRUE
set_config_cpm <- function(...) {
tidyr::expand_grid(
params_fmri_tasks,
params_xcpd,
hypers_cpm
) |>
dplyr::filter({{ params_subset }}) |>
dplyr::filter(...) |>
dplyr::mutate(
file_fc = rlang::syms(
sprintf(
Expand Down
12 changes: 10 additions & 2 deletions _scripts/g_factor.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ options(clustermq.scheduler = "sge")
options(clustermq.template = "clustermq.tmpl")
tar_source()

config_cpm <- set_config_cpm(
atlas == "Schaefer217",
thresh_method == "alpha",
thresh_level == 0.01
)

n_vars_total <- 76
n_steps <- 20

Expand Down Expand Up @@ -70,7 +76,7 @@ list(
scores_g_imp
),
tarchetypes::tar_map(
config_files(),
config_cpm,
names = !starts_with("file"),
tarchetypes::tar_rep(
cpm_result,
Expand All @@ -83,7 +89,9 @@ list(
thresh_method, thresh_level
),
.keep = "unused"
)
),
batches = 4,
reps = 5
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion _scripts/predict_phenotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tar_option_set(
tar_source()

cpm_branches <- tarchetypes::tar_map(
config_files(),
set_config_cpm(),
names = !starts_with("file"),
tarchetypes::tar_rep(
cpm_result,
Expand Down

0 comments on commit e95d57f

Please sign in to comment.