Skip to content

Releases

targetfy v2.1

Choose a tag to compare

@Athospd Athospd released this 22 Nov 21:15

v2.1 adds the targets tools deferred from v2, and tests the paths v2 couldn't run: crew workers, Quarto, torch, keras and web inputs.

New

Scripts that render documents. A script that calls rmarkdown::render() or quarto::quarto_render() now converts to tar_render() or tar_quarto(). A loop that renders a document once per parameter set converts to tar_render_rep() or tar_quarto_rep().

  • Your document is never edited: a copy reads Targets with tar_read().
  • Tested with both R Markdown and Quarto, three reports each.

Data targets can't see change. Database and API reads (dbGetQuery(), dbReadTable(), req_perform(), GET()...) are flagged, with two options:

  • tar_change(), which reruns the read when a cheap check changes, such as a row count or max(updated_at);
  • tar_age(), which reruns it once the result is older than a set time.

The input-change check now also changes local SQLite files. With tar_change() the Pipeline passes; with a plain Target, an untracked database read fails as a hidden dependency.

renv. When the project has an renv.lock, the check lists the packages the Pipeline uses that the lockfile doesn't record. renv misses packages named as strings, as in tar_option_set(packages = "dplyr"). Two new Enhancements:

  • tar_renv(), so the next renv::snapshot() records those packages;
  • tar_github_actions(), which runs the Pipeline on GitHub on every push.

Now tested

Path Result
crew workers with tar_hook_before(): equivalent. With options() only above list(), 3 Targets mismatch, because workers never run that line
torch, keras tar_format() works. With plain RDS, the model breaks as soon as a Target reads it back from the store
format = "url" equivalent against a real URL, and not out of date right after the build. URLs are listed as inputs the input-change check can't test
Quarto tar_quarto_rep() is equivalent to a quarto_render() loop

Fixes

  • A Pipeline that fails to build now names each failing Target and its error, not just targets' generic debugging advice.
  • A document copy for a targets_<name>.R Pipeline must read from that Pipeline's store: tar_read(x, store = "_targets_<name>").
  • Quarto's <document>_files/ folder no longer counts as a mismatched output.
  • tar_render_rep(report, ...) creates a Target named report_params, so no helper may take that name.
  • Calls like knitr::opts_chunk$set() are no longer reported as display-only.

Setup notes (Windows)

  • Quarto: an app started before Quarto was installed won't see it on the PATH until it restarts.
  • keras: build r-keras from a python.org or winget Python. R can't load the Microsoft Store Python's DLL ("Access is denied"), and reticulate may pick that one on its own. install_keras() defaults to Python 3.9–3.11.
  • crew: with crew 1.3, use targets 1.9 or later.

Full test suite: 239 tests.

targetfy v2

Choose a tag to compare

@Athospd Athospd released this 22 Nov 19:17

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.

targetfy v1

Choose a tag to compare

@Athospd Athospd released this 22 Nov 04:08

The first release of targetfy, a Claude Code skill that turns existing R scripts into an equivalent {targets} pipeline, checks that it really is equivalent, then offers optional Enhancements.

Install

git clone https://github.com/Athospd/targetfy.git ~/.claude/skills/targetfy

Then, in Claude Code: /targetfy my_script.R, or ask it to convert your R script(s) to targets.

Requires R >= 4.1 with targets (>= 1.12), tarchetypes, callr and jsonlite. targetfy never installs packages.

What's in v1

Conversion

  • One or more .R scripts, in the order you list them, become _targets.R plus one functions file per script (R/<script>_functions.R). Each meaningful object becomes a Target.
  • library() calls go into tar_option_set(packages = ...). Input files are tracked, output files become file Targets, and saveRDS → readRDS handoffs between scripts become direct dependencies.
  • Bare plots become plot Targets. Console-only lines (View, help, print, setwd, install.packages…) are dropped and listed in the report.
  • It never modifies an existing file. When _targets.R already exists, it writes targets_<name>.R with its own store.
  • A script sitting loose in Downloads or Desktop gets its own Working Folder, holding a copy of it and only the files it reads.

Verification (scripts/check.R)

  • You choose between Run and compare (the Equivalence Check) and Only validate the files (the Static Check). The Equivalence Check runs your scripts and the Pipeline in throwaway copies and compares every mapped Target with all.equal(), and every written file by content.
  • Stochastic Targets (random numbers, model seeds) are detected and compared by structure.
  • Up to 3 fix-and-recheck rounds.
  • It keeps going. Scripts that fail on their own fall back to the Static Check, with the failing line reported. A missing package is reported as not_checked, never as a bug in the Conversion.

Choosing R (scripts/find-r.R)

  • Finds every R installation, loads targetfy's and your scripts' packages in each (including set_engine("<pkg>") engines), and picks the one where everything loads. This catches version conflicts like an outdated yardstick in the Rscript on your PATH.

Report and graph

  • targetfy-report.md records every Target's check result, every dropped or changed line, and what couldn't be verified and why.
  • tar_glimpse() opens the Pipeline's graph in your browser.

Enhancement wizard

  • After a passing check, it offers storage formats, dynamic branching and {crew} parallel workers, one at a time. Each one is re-checked and undone if it breaks Equivalence.

Not yet supported

.Rmd, .qmd and .ipynb notebooks, a Targets granularity setting, and stricter comparison with {waldo}. See docs/design-v1.md.

House style: a pinned copy of targets-r-skill by Ulrich Atz (CC-BY-4.0).