targets
Overview
The {targets}
R package offers a superior workflow compared to a script-based approach, addressing several common challenges:
- Managing a sequence of computational steps :
{targets}
allows you to define a pipeline of computational steps, specifying the dependencies and relationships between them. - Selective updates : With
{targets}
, you only need to update the specific steps affected by a change. It intelligently determines which steps are affected and updates them accordingly, saving time and computational resources. - Ensuring validity of results :
{targets}
automatically tracks the relationships between steps and ensures that the results at the end of the pipeline remain valid, even if intermediate steps change.
Key advantages of the {targets}
workflow over script-based approaches include:
- Reproducibility : By explicitly defining dependencies,
{targets}
ensures that changes in one step trigger the re-evaluation of dependent steps, maintaining reproducibility. - Efficiency : Instead of rerunning all scripts,
{targets}
selectively executes only the affected steps, optimizing computational efficiency. - Scalability :
{targets}
provides a clear overview of dependencies, making it easier to manage and scale complex workflows with numerous scripts. - Simplified file management :
{targets}
automatically manages input and output files, removing the burden of manually tracking file dependencies and their locations.
Slides
Open the slides in a new tab here.
Exercises
- Download this R project as a zip file (green “Code” button -> “Download ZIP”). (If you are familiar with git/github, feel free to clone it directly.)
- Examine the file structure, the code, the
_targets.R
file. - Run
tar_make()
. - Examine everything again and see what’s new.
- Put the Poisson regression and table you made earlier into functions and add to the appropriate folders.
- Add
tar_target()
calls to_targets.R
. - Add a code chunk to output the table in
my-analysis.qmd
. - Run
tar_outdated()
. - Run `tar_make().
Resources
- The user manual is a great resource for learning more