Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom names for branched targets #672

Closed
wlandau opened this issue Oct 21, 2021 Discussed in #668 · 5 comments
Closed

Allow custom names for branched targets #672

wlandau opened this issue Oct 21, 2021 Discussed in #668 · 5 comments

Comments

@wlandau
Copy link
Member

wlandau commented Oct 21, 2021

Discussed in #668

Originally posted by JohannesNE October 21, 2021
It would be very convenient to allow custom names of branched targets. Example:

I have 3 files in data/: data/churn.csv data/churn2500.csv and data/churn5000.csv

My pipeline looks like this:

list(
  tar_files(churn_file, list.files("data", full.names = TRUE)),
  tar_target(churn_data, read.csv(churn_file), map(churn_file), iteration = "list"),
  tar_target(churn_rows, nrow(churn_data), map(churn_data), iteration = "list")
)
names(tar_read(churn_data))
# [1] "churn_data_123e0f60" "churn_data_b5c463de"
# [3] "churn_data_f4ac93c0"

It would be very useful to assign names to churn_data branches based on churn_file, so I know which file each branch comes from. Also churn_rows could just inherit names from churn_data

The ideal behaviour would be something like this:

list(
  tar_files(churn_file, list.files("data", full.names = TRUE)),
  tar_target(churn_data, read.csv(churn_file), map(churn_file), iteration = "list", name = basename(churn_file)),
  tar_target(churn_nrow, nrow(churn_data), map(churn_data), iteration = "list", inherit_name = TRUE)
)
names(tar_read(churn_data))
# [1] "churn.csv"     "churn2500.csv"
# [3] "churn5000.csv"
names(tar_read(churn_nrow))
# [1] "churn.csv"     "churn2500.csv"
# [3] "churn5000.csv"
```</div>
@wlandau
Copy link
Member Author

wlandau commented Oct 21, 2021

For a second I thought this would actually be possible, then realized it would get messy to handle cross().

@wlandau wlandau closed this as completed Oct 21, 2021
@markpayneatwork
Copy link

Could an alternative way forward be that the name argument proposed above is function, taking the same arguments as pattern. The user is (fully!) responsible for generating the name, given the arguments.

@stuvet
Copy link
Contributor

stuvet commented Aug 22, 2022

I do this with tarchetypes::tar_eval instead - I give an entirely custom name to anything but the simplest standalone target & can easily filter output to examine an individual branch.

It gets a bit awkward when the input target is, itself, dynamic - e.g. pull a mutable table of metadata from an external website & run a set of targets across each row, naming the branch according to the value of some column in the table. You can't always predict the next name you'd need & I don't want to invalidate all my downstream targets if the website goes down temporarily. I work around this one by caching the table as part of the pipeline, & reading from the cache before the pipeline next starts to get metadata to use in the values argument of tarchetypes::tar_eval (beware of the security implications - need to consider which characters you'll allow). Not perfect as you have to nurse it through the first run, & the dependent targets will sometimes be 1 run behind the current value of the initial table, but it works fine for my purposes -> thousands of targets all with static branching based on a dynamic table.

@GiuseppeTT
Copy link

I like @markpayneatwork's idea. It is exactly how I thought it should work before finding this GitHub issue.

You could also offer functions for common approaches like concatenating input values.

@jospueyo
Copy link

I was about to propose this, when I found this closed issue. Knowing whether this is possible or how to implement this is far beyond my skills. However, I fully support any attempt to achieve this. And count on me if I can help anyhow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants