Skip to main content
v2026.11,986 entries · CC-BY 4.0

targets R Package: Install, tar_make() and Pipeline Workflow

How to install the targets R package, run a pipeline with tar_make(), read results and see exactly which edits trigger reruns, with a worked example.

Written and maintained by CASRAI Editorial Board

Published

On this page

The targets package is an R package for building reproducible, Make-like analysis pipelines: you declare each step of an analysis as a target, run the whole pipeline with tar_make(), and the package skips every step whose code, inputs and upstream results have not changed since the last run. Install it with install.packages("targets"), create a pipeline script named _targets.R, and use tar_visnetwork() to inspect, tar_make() to run and tar_read() to read results. This guide follows the package documentation and walks through a complete worked example.

What targets is used for in research

The CRAN description calls targets a Make-like pipeline tool for statistics and data science in R. It skips tasks that are already up to date, runs the computation that is needed in parallel, and treats files as R objects. The package borrows ideas from GNU Make and from its predecessor drake. Its author and maintainer is William Michael Landau, and the package is released under the MIT licence.

For a researcher the practical value is that an analysis becomes a graph of named steps instead of a script that must be rerun from the top. When you change one function or one data file, targets works out which results are now stale and recomputes only those. That makes the relationship between raw data, code and each reported figure explicit and re-checkable, which is the working definition of computational reproducibility. The package is described in a peer-reviewed software paper: Landau, W. M. (2021), “The targets R package: a dynamic Make-like function-oriented pipeline toolkit for reproducibility and high-performance computing”, Journal of Open Source Software 6(57), 2959, published 15 January 2021 (doi:10.21105/joss.02959).

Install or access targets

The package documentation at docs.ropensci.org/targets lists three official routes. Each is a single R command, run once in your R session.

Route Command When to use it
CRAN release install.packages("targets") The standard route for the released version.
Development version with pak pak::pkg_install("ropensci/targets") When you need the development version from GitHub.
rOpenSci R-universe install.packages("targets", repos = "https://dev.ropensci.org") The development version as a binary from rOpenSci’s repository.

The CRAN page lists version 1.12.0, published on 9 February 2026, and requires R 3.5.0 or later. For distributed computing the documentation points to the crew package, version 0.4.0 or later. If you are new to installing R packages, see the guide on how to install libraries in R. If you also need to pin package versions for a project, the renv guide covers per-project libraries, and devtools covers installing development packages.

Step-by-step: build and run your first pipeline

The walkthrough in the targets user manual fits a linear model to the built-in airquality data (ozone against temperature) and plots it. The project has three files: a pipeline script, a functions file and a data file.

Step 1. Create the project files

You can generate a template pipeline script with use_targets(), which writes _targets.R into your project. The walkthrough version of the script is:

library(targets)
library(tarchetypes)
tar_source()
tar_option_set(packages = c("readr", "dplyr", "ggplot2"))
list(
  tar_target(file, "data.csv", format = "file"),
  tar_target(data, get_data(file)),
  tar_target(model, fit_model(data)),
  tar_target(plot, plot_model(model, data))
)

The functions the targets call live in R/functions.R, which tar_source() loads:

get_data = function(file) {
  read_csv(file, col_types = cols()) %>%
    filter(!is.na(Ozone))
}

fit_model = function(data) {
  lm(Ozone ~ Temp, data) %>%
    coefficients()
}

plot_model = function(model, data) {
  ggplot(data) +
    geom_point(aes(x = Temp, y = Ozone)) +
    geom_abline(intercept = model[1], slope = model[2])
}

In the manual these functions are written with the left-arrow assignment; plain = is shown here, which also defines a function. They use the %>% operator; the guide on the pipe in R explains it. The data file data.csv has the columns Ozone, Solar.R, Wind, Temp, Month and Day.

Three details matter. Each tar_target() takes a name and a command, and later targets refer to earlier ones by name, which is how targets infers the dependency graph. The first target uses format = "file" so that targets tracks the file itself, not only its path. Packages the commands need are declared once, in tar_option_set(packages = ...).

Step 2. Inspect the pipeline before running it

List each target and its command with tar_manifest(fields = all_of("command")). The walkthrough shows four rows: file (the string “data.csv”), data (get_data(file)), model (fit_model(data)) and plot (plot_model(model, data)). Then call tar_visnetwork() to draw the dependency graph and confirm that the arrows match what you intended.

Step 3. Run the pipeline

Run tar_make(). It executes the pipeline in a new R process and runs only the targets that are out of date. On the first run every target is dispatched and completed, and the console ends with a line such as “ended pipeline [855ms, 4 completed, 0 skipped]” (the timings in your session will differ).

Step 4. Read the results

Use tar_read(plot) to return the stored plot, or tar_load() to load a target into your session under its own name. Because results are stored by the pipeline rather than recreated in your interactive session, the same call works in a later session without rerunning the analysis.

Output and how to read it

The console output of tar_make() gives a line per target (“dispatched”, then “completed” with elapsed time and stored size) and a closing summary of how many targets completed and how many were skipped. That summary is the quickest check that incremental rebuilding is working. If you run tar_make() again with nothing changed, the documentation shows “skipped pipeline [68ms, 4 skipped]”, so no computation reran.

tar_outdated() answers the question “what would rerun?” without running anything. It returns character(0) when every target is current, or the names of the stale targets. The walkthrough demonstrates two cases:

  • After editing plot_model() (it adds theme_gray(24)), tar_outdated() returns “plot”, and the next tar_make() reports “1 completed, 3 skipped”.
  • After overwriting data.csv with the first 100 rows of airquality, tar_outdated() returns “file”, “plot”, “data” and “model”, and the next tar_make() reports “4 completed, 0 skipped”.

The data table below summarises these four situations from the walkthrough. The documentation describes the rules that decide whether a target reruns as “cues”, and tar_cue() can suppress some of them.

The second case shows why format = "file" matters. Because file is a file target, a change to the contents of data.csv invalidates it and everything downstream. Without that format, targets would not notice the data had changed.

In practice this means a long analysis can be re-run after a small change at the cost of only the affected steps. A reviewer or collaborator can inspect the same graph with tar_visnetwork(), see which results depend on which inputs, and confirm with tar_outdated() that the stored results correspond to the current code and data before any numbers are reported.

Troubleshooting

The following points come from the walkthrough and the user manual’s help chapter at books.ropensci.org/targets/help.html.

Symptom What to check
You are unsure the pipeline is wired as intended Run tar_manifest() and tar_visnetwork() before tar_make().
Editing a data file does not trigger a rerun Declare the file as a target with format = "file".
targets cannot find your pipeline script The default script is _targets.R; use tar_config_set() or the script argument to point elsewhere.
A package function is not found inside a target Declare the package in tar_option_set(packages = ...).
Your own functions are not found Load them with tar_source() or source("R/functions.R") in _targets.R.

targets is free and open source. The CRAN page names two tools it is built on or borrows from; the table below states only what that page says.

Tool Relationship to targets (per the CRAN page)
GNU Make targets is a Make-like tool and borrows ideas from it.
drake The predecessor package that targets borrows from; the CRAN page cites the drake JOSS paper (doi:10.21105/joss.00550).

Frequently asked questions

What does tar_make() do?

It runs the pipeline defined in _targets.R in a new R process and executes only the targets that are out of date, skipping the rest.

How do I read a result from a targets pipeline?

Use tar_read(name) to return a target’s stored value, or tar_load(name) to load it into the session.

How do I check which targets are out of date?

Run tar_outdated(). It returns character(0) when everything is current, otherwise the names of the targets that would rerun.

Which R version does targets need?

The CRAN page lists R 3.5.0 or later for version 1.12.0 (published 9 February 2026).

How do I cite the targets package?

Cite the Journal of Open Source Software paper, Landau (2021), doi:10.21105/joss.02959, and the CRAN package DOI, 10.32614/CRAN.package.targets.

Sources

  • rOpenSci, targets package documentation, https://docs.ropensci.org/targets/ (read 2026-11-15).
  • Landau, W. M., The targets R Package User Manual, walkthrough chapter, https://books.ropensci.org/targets/walkthrough.html (read 2026-11-15); help chapter, https://books.ropensci.org/targets/help.html.
  • CRAN, targets package page, https://cran.r-project.org/web/packages/targets/index.html (read 2026-11-15).
  • Landau, W. M. (2021). The targets R package. Journal of Open Source Software, 6(57), 2959, https://joss.theoj.org/papers/10.21105/joss.02959 (read 2026-11-15).

Data: targets R package: effect of edits on reruns in the documentation walkthrough

Compiled from the targets user manual walkthrough: for each situation in the four-target example pipeline (file, data, model, plot), the number of targets that completed and were skipped, and which targets tar_outdated() lists.

targets R package: effect of edits on reruns in the documentation walkthrough
SituationTargets completed (count)Targets skipped (count)Targets listed by tar_outdated()
First tar_make() run40not shown in the walkthrough
tar_make() again with nothing changed04character(0)
Edit plot_model() in R/functions.R13plot
Overwrite data.csv with a 100-row subset40file, plot, data, model

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about targets R Package: Install, tar_make() and Pipeline Workflow

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →