Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

Commit

Permalink
Better combine function
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zhang <[email protected]>
  • Loading branch information
psychelzh committed May 3, 2023
1 parent 64f4d33 commit 94ddaba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
14 changes: 10 additions & 4 deletions R/utils-targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,14 @@ targets_sample_tasks <- function(num_tasks, data,
)
}

clean_combined <- function(df, name, to) {
df |>
mutate(id = str_remove(id, name)) |>
separate(id, c(NA, to), convert = TRUE)
combine_targets <- function(name, targets, cols_targets) {
name <- deparse1(substitute(name))
tarchetypes::tar_combine_raw(
name,
targets[[name]],
command = bind_rows(!!!.x, .id = "id") |>
mutate(id = str_remove(id, .(name))) |>
separate(id, c(NA, .(cols_targets)), convert = TRUE) |>
bquote()
)
}
20 changes: 4 additions & 16 deletions _targets_g_invariance.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,7 @@ list(
)
),
g_invariance,
tarchetypes::tar_combine(
scores_g,
g_invariance$scores_g,
command = bind_rows(!!!.x, .id = "id") |>
clean_combined(
"scores_g",
c("num_vars", "id_pairs")
)
),
combine_targets(scores_g, g_invariance, c("num_vars", "id_pairs")),
tar_target(
scores_g_cor_pairwise,
scores_g |>
Expand Down Expand Up @@ -100,14 +92,10 @@ list(
mutate(user_id = seq_len(n()), .before = 1L)
),
g_invariance_random,
tarchetypes::tar_combine(
combine_targets(
scores_g_random,
g_invariance_random$scores_g_random,
command = bind_rows(!!!.x, .id = "id") |>
clean_combined(
"scores_g_random",
c("num_vars", "id_pairs")
)
g_invariance_random,
c("num_vars", "id_pairs")
),
tar_target(
scores_g_cor_pairwise_random,
Expand Down

0 comments on commit 94ddaba

Please sign in to comment.