Skip to content

targetfy v2

Choose a tag to compare

@Athospd Athospd released this 22 Nov 19:17
· 3 commits to main since this release

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 params become 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() or tar_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 into tar_option_set() (seed, memory, error = "null", imports);
  • options() lines go before the targets, with tar_hook_before() for parallel workers.

More targets/tarchetypes tools:

  • branching candidates now say which tool fits: pattern = map(), tar_map() with tar_combine(), tar_group_by(), or tar_rep();
  • torch/keras models get a tar_format(), and connections never become targets;
  • web inputs use format = "url" or tar_download();
  • targets_<name>.R pipelines get a _targets.yaml project;
  • the report adds tips for tar_watch(), tar_workspace() and tar_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 = TRUE chunks 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.pdf behind.

Notes

  • Not exercised on this release's test machine:
    • crew workers (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-invalidation or --max-inputs for slow scripts.
  • See docs/design-v2.md for the decisions and GLOSSARY.md for the new terms.

Full test suite: 202 tests across 17 fixtures.