ropensci / drake

An R-focused pipeline toolkit for reproducibility and high-performance computing
https://docs.ropensci.org/drake
GNU General Public License v3.0
1.34k stars 128 forks source link

How the use the name of a dynamic subtarget? #1336

Closed matthiasgomolka closed 3 years ago

matthiasgomolka commented 3 years ago

Prework

Question

I use dynamic targets in my plan. One of those targets writes files to disk. So I get one file per subtarget. Now I need to make sure that these files have distinguishible names. It would be nice if I could somehow get the cryptic name of the subtarget, since this would make it easy to bring the subtargets and the files written to disk together.

I played around with timestampts but this is not safe as it sometimes happens that two subtargets try to create a file at the same moment.

I suppose, this information is "somewhere". Is it also accessible within a dynamic target?

Reproducible example

Does not apply here.

wlandau commented 3 years ago

id_chr() allows you to get the name of the sub-target while make() or r_make() is running. That should allow you to name files in a way that matches your targets. Another alternative is to generate a universally unique identifier (UUID) with the uuid package or tempfile().