I want to use another target to generate the values for tar_map(), this is to avoid end users to edit the code and just editing the config file. I tried this:
library(targets)
tar_script({
library(tarchetypes)
list(
tar_target(config, c("a", "b", "c")),
tar_map(
values = list(configs = config),
tar_target(result, paste0(configs, "1"))
)
)
})
tar_make()
#> Error:
#> ! Error running targets::tar_make()
#> Error messages: targets::tar_meta(fields = error, complete_only = TRUE)
#> Debugging guide: https://books.ropensci.org/targets/debugging.html
#> How to ask for help: https://books.ropensci.org/targets/help.html
#> Last error: object 'config' not found
Created on 2024-02-06 with reprex v2.1.0
Targets does not find the first target. If I use tar_read(config) works, but then the dependency is not recognized so if config is changed, the target is not updated.
The error happens because
configis a target computed during the pipeline, whereastar_map()is static branching that happens before the pipeline. You can use dynamic branching to branch over theconfigtarget: https://books.ropensci.org/targets/dynamic.htmlThe static branching version of this would define
configas a global variable that exists before the pipeline begins.