Repository navigation
targetfy v2
targetfy v2 converts R notebooks as well as scripts. It also handles scripts that aren't DAGs, and its check now proves that the pipeline reruns when its inputs change.
Watch: what's new in v2, in 45 seconds
Highlights
Notebooks as input. .qmd, .Rmd, .md and R-kernel .ipynb files are converted like .R scripts.
- What counts as code follows what rendering would run.
- YAML
paramsbecome a Target. - Code runs from the notebook's own folder, as knitting does.
- Problems are reported at notebook lines (
report.qmd:42,nb.ipynb:cell 3, line 2). - A new Render the document Enhancement builds the report from the pipeline with
tar_render()ortar_quarto().
Scripts that aren't DAGs. A new flow scan (scripts/read.R) reads the code without running it. It finds what a naive one-variable-one-target conversion would get wrong:
- variables changed after another step used them, which become one Target per version;
- files read and then overwritten, which are written to a new path instead;
- loops that carry state, which stay whole;
- loops that could be branched;
- global side effects;
- names used before they're defined.
The Invalidation Check. After the outputs match, the check changes each input file in a sandbox. It then verifies that the targets which rerun are exactly those whose results change in the original script. An input read but not tracked fails as a hidden dependency, instead of going stale later. Thanks to the LinkedIn commenter who suggested it.
Stronger checks. The check now fails a pipeline that:
- has a cycle;
- is out of date right after it's built;
- overwrites its own input.
Pipeline setup from script code:
- functions defined in scripts and sourced helpers go into
tar_source(); set.seed(),rm()/gc(),try()and in-house packages go intotar_option_set()(seed,memory,error = "null",imports);options()lines go before the targets, withtar_hook_before()for parallel workers.
More targets/tarchetypes tools:
- branching candidates now say which tool fits:
pattern = map(),tar_map()withtar_combine(),tar_group_by(), ortar_rep(); torch/kerasmodels get atar_format(), and connections never become targets;- web inputs use
format = "url"ortar_download(); targets_<name>.Rpipelines get a_targets.yamlproject;- the report adds tips for
tar_watch(),tar_workspace()andtar_outdated().
Tested against a real repository (targets-live):
- chunk labels like
{r, fig.height=8}are parsed correctly; - every version of a reassigned variable is listed;
cache = TRUEchunks are flagged;- files that are already targets code (pipelines,
tar_read()reports) are recognised; - failing display-only console leftovers are skipped and reported, so a real 492-line tidymodels notebook now runs end to end;
- plots no longer leave an
Rplots.pdfbehind.
Notes
- Not exercised on this release's test machine:
crewworkers (tar_hook_before()was tested sequentially);tar_quarto()(Quarto not on the PATH;tar_render()was tested);- the torch/keras formats;
format = "url".
- The Invalidation Check runs the scripts once more per input file. Use
--skip-invalidationor--max-inputsfor slow scripts. - See
docs/design-v2.mdfor the decisions andGLOSSARY.mdfor the new terms.
Full test suite: 202 tests across 17 fixtures.