Comments (7)
tar_map()
uses static branching, so it does its thing before the pipeline runs. In other words, the label1
target may not even exist yet when tar_map()
is called. To define new targets based on the values of upstream targets, you can use dynamic branching.
from tarchetypes.
I did, but I didn't realize a response from me would be helpful. Substituting vectors of variable length are out of scope for static branching, but it sounds like you found something that works for you. The underlying mechanism is substitute()
, and it looks the deparsed vectors are being substituted correctly. Seems like you can continue with your workaround.
from tarchetypes.
values
should be a named data frame or list, where columns/elements are atomic vectors or symbol lists. The names
argument uses tidyselect
to choose among names(values)
to create the target names. The values
list you created was nested enough that targets
did not try to parse it into a set of friendly names. That sort of thing gets tricky if values
gets complicated.
Here are examples similar to yours.
targets::tar_script({
list(
tarchetypes::tar_map(
values = list(label1 = c("foo", "bar"), label2 = c("test1", "test2")),
names = label1,
targets::tar_target(b, label2)
)
)
})
targets::tar_manifest()
#> # A tibble: 2 x 3
#> name command pattern
#> <chr> <chr> <chr>
#> 1 b_foo "\"test1\"" <NA>
#> 2 b_bar "\"test2\"" <NA>
targets::tar_script({
list(
tarchetypes::tar_map(
values = list(label1 = c("foo", "bar"), label2 = c("test1", "test2")),
names = starts_with("label"),
targets::tar_target(b, label2)
)
)
})
targets::tar_manifest()
#> # A tibble: 2 x 3
#> name command pattern
#> <chr> <chr> <chr>
#> 1 b_bar_test2 "\"test2\"" <NA>
#> 2 b_foo_test1 "\"test1\"" <NA>
Created on 2021-04-08 by the reprex package (v1.0.0)
from tarchetypes.
Thanks for the quick reply and all your amazing work :). The thing is that in my real project I want to specifically map vectors of variable length. In my code its a setting specifying which variables the data set that I work with should be collapsed over (can be many). So I first run the code for a = c("foo", "bar")
and then separately for a = c("test")
. Your code is creating two separate targets, one for each element in label2
.
I read in the help file that as you say values should be a list of vectors/data frame, but as you can see the nested list that I supplied did result in the correct mapping, only naming is wrong. b_foo
returns "foo-bar"
and b_bar
returns "test1-test"
.
The code below works though:
targets::tar_dir({ # tar_dir() runs code from a temporary directory.
targets::tar_script({
list(
tarchetypes::tar_map(
values = list(a = list(c("foo", "bar"), c("test1"), c(1, 2, 3)), names = c("foo", "test", "integers")),
names = names,
targets::tar_target(b, paste(a, collapse = "-"))
)
)
})
targets::tar_manifest()
})
name command pattern
<chr> <chr> <chr>
1 b_integers "paste(c(1, 2, 3), collapse = \"-\")" NA
2 b_test "paste(\"test1\", collapse = \"-\")" NA
3 b_foo "paste(c(\"foo\", \"bar\"), collapse = \"-\")" NA
Not sure why it works to supply a vector of names as values and then assign it to names, but not to assign a character vector immediately (as the help page for tar_map
says is possible).
from tarchetypes.
Ping @wlandau, not sure if you saw my reply?
from tarchetypes.
Great, was thinking if perhaps my solution was perhaps the result of a bug but thats great. Thanks!
from tarchetypes.
targets::tar_script({
list(
tarchetypes::tar_map(
values = list(label1 = c("foo", "bar"), label2 = c("test1", "test2")),
names = label1,
targets::tar_target(b, label2) )
})
In this example that you @wlandau provided, could the element label1 be defined in another single target?
I tried creating the target and referring to it with label1 = rlang::sym("name_target")
without success.
Thanks!
from tarchetypes.
Related Issues (20)
- Local persistence of cloud-backed file targets HOT 5
- `tar_quarto()` always ends normally for quarto project even if there is error HOT 3
- `tar_quarto()` ignores `output_dir` in _quarto.yml when passed an individual file
- combine tar_cue_age with a conditional statement HOT 4
- Rep-specific seeds in tar_rep(), tar_map_rep(), etc. HOT 5
- optional garbage collection between reps of the `tar_rep*()` functions HOT 1
- tar_change repository not considered for change part
- Branches not in metadata: branches out of range
- GitHub interactions are temporarily limited because the maintainer is out of office.
- tar_cross() HOT 2
- Bug: `tar_quarto_rep()` throws an error if used together with `future::plan()` from _targets.R template HOT 1
- Support Quarto profiles? HOT 10
- Expose `tar_render()`, `tar_quarto()` and similar functions to the `deps` argument of `tar_target_raw()` HOT 8
- Errors and warnings with Quarto
- tar_quarto_rep doesn't work on reports in subdirectories HOT 2
- `retrieval = "none"` in quarto target factories HOT 2
- [general] Use `tar_rep()` and `tar_rep2()` inside of `tar_map()` HOT 2
- Allow trailing comma in `tar_map()` HOT 1
- Let `tar_map()` substitute more fields, e.g., `priority` HOT 2
- Safely allow tar_quarto() etc. to run the report from a custom working directory HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tarchetypes.