tar_map() losing names if values is a data frame with a list column #105
-
I am trying to pass a list of parameters down for processing in tar_map(), iterating over several models with different parameters. The code below shows that though I define parameters as named list, the names are stripped when passing it to a target.
As you can see the lists passed to
where each element of
These names are missing in my target. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
targets::tar_script({
MODELS <- tibble::tribble(
~NAME, ~PARAMS,
1, quote(list(a = 3, b = 5, c = 25)), # quote()
2, quote(list(a = 0, b = 1, c = 42)) # quote()
)
list(
tarchetypes::tar_map(
values = MODELS,
names = NAME,
targets::tar_target(params, PARAMS)
)
)
})
targets::tar_manifest()
#> # A tibble: 2 × 2
#> name command
#> <chr> <chr>
#> 1 params_1 list(a = 3, b = 5, c = 25)
#> 2 params_2 list(a = 0, b = 1, c = 42) Created on 2022-09-05 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
-
Thank you, it does work. Looks weird, but works. |
Beta Was this translation helpful? Give feedback.
-
We have a related question: we're generating parameters using linreg <- 5
quantreg <- 50
targets::tar_script({
MODELS <- tibble(
NAME = 1:16,
PARAMS = map(
transpose(expand_grid(
trainer = rlang::syms(c("linreg", "quantreg")),
ahead = 1:4,
pop_scaling = c(TRUE, FALSE)
)), enquote
)
)
list(
tar_map(
values = MODELS,
names = NAME,
tar_target(
params,
command = {
print(PARAMS)
}
)
)
) which produces r$> tar_manifest()
/
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Loading required package: epiprocess
/
Attaching package: 'epiprocess'
The following object is masked from 'package:stats':
filter
Loading required package: parsnip
# A tibble: 16 × 2
name command
<chr> <chr>
1 params_10 "{\n print(base::quote(list(quantreg, 1L, FALSE)))\n }"
2 params_11 "{\n print(base::quote(list(quantreg, 2L, TRUE)))\n }"
3 params_12 "{\n print(base::quote(list(quantreg, 2L, FALSE)))\n }"
4 params_13 "{\n print(base::quote(list(quantreg, 3L, TRUE)))\n }"
5 params_1 "{\n print(base::quote(list(linreg, 1L, TRUE)))\n }"
6 params_14 "{\n print(base::quote(list(quantreg, 3L, FALSE)))\n }"
7 params_2 "{\n print(base::quote(list(linreg, 1L, FALSE)))\n }"
8 params_15 "{\n print(base::quote(list(quantreg, 4L, TRUE)))\n }"
9 params_3 "{\n print(base::quote(list(linreg, 2L, TRUE)))\n }"
10 params_16 "{\n print(base::quote(list(quantreg, 4L, FALSE)))\n }"
11 params_4 "{\n print(base::quote(list(linreg, 2L, FALSE)))\n }"
12 params_5 "{\n print(base::quote(list(linreg, 3L, TRUE)))\n }"
13 params_6 "{\n print(base::quote(list(linreg, 3L, FALSE)))\n }"
14 params_7 "{\n print(base::quote(list(linreg, 4L, TRUE)))\n }"
15 params_8 "{\n print(base::quote(list(linreg, 4L, FALSE)))\n }"
16 params_9 "{\n print(base::quote(list(quantreg, 1L, TRUE)))\n }"
r$> MODELS$PARAMS[[1]]
base::quote(list(trainer = linreg, ahead = 1L, pop_scaling = TRUE)) |
Beta Was this translation helpful? Give feedback.
-
it looks like something isnt reading correctly in the network node names when constructing the visnetwork/mermaid visuals, manifest looks ok Are the network plots printing the descriptions? targets::tar_dir({
targets::tar_script({
MODELS <- tibble::tribble(
~NAME, ~PARAMS,
1, list(a = 3, b = 5, c = 25),
2, list(a = 0, b = 1, c = 42)
) |>
dplyr::mutate(
dplyr::across(-NAME, ~purrr::map(.x, quote))
)
list(
tarchetypes::tar_map(
values = MODELS,
names = NAME,
targets::tar_target(params, PARAMS)
)
)
})
targets::tar_mermaid(targets_only = TRUE)
})
#> [1] "graph LR"
#> [2] " style Legend fill:#FFFFFF00,stroke:#000000;"
#> [3] " style Graph fill:#FFFFFF00,stroke:#000000;"
#> [4] " subgraph Legend"
#> [5] " direction LR"
#> [6] " x2db1ec7a48f65a9b([\"\"Outdated\"\"]):::outdated --- xd03d7c7dd2ddda2b([\"\"Stem\"\"]):::none"
#> [7] " end"
#> [8] " subgraph Graph"
#> [9] " direction LR"
#> [10] " xa28dc0b612a56289([\"params_1<br>1 expr\"]):::outdated --> xa28dc0b612a56289([\"params_1<br>1 expr\"]):::outdated"
#> [11] " x121c500316efbe56([\"params_2<br>2 expr\"]):::outdated --> x121c500316efbe56([\"params_2<br>2 expr\"]):::outdated"
#> [12] " end"
#> [13] " classDef outdated stroke:#000000,color:#000000,fill:#78B7C5;"
#> [14] " classDef none stroke:#000000,color:#000000,fill:#94a4ac;"
#> [15] " linkStyle 0 stroke-width:0px;"
#> [16] " linkStyle 1 stroke-width:0px;"
#> [17] " linkStyle 2 stroke-width:0px;" Created on 2024-07-09 by the reprex package (v2.0.1) # A tibble: 2 × 3
name command description
<chr> <chr> <chr>
1 params_1 expr 1 expr
2 params_2 expr 2 expr |
Beta Was this translation helpful? Give feedback.
tar_map()
substitutes simple objects, symbois, and expressions. Try wrapping your lists inquote()
to treat them as expression objects.Created on 2022-09-05 with reprex v2.0.2