From rap
Configure {targets} build automation for a RAP R project pipeline
How this skill is triggered — by the user, by Claude, or both
Slash command
/rap:rap-pipelineThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
```text
$ARGUMENTS
You are configuring build automation for a RAP R project using the {targets} package. Build automation is a Silver RAP requirement (S1: minimal manual intervention) — it replaces manually sourcing scripts in order with a dependency-aware pipeline that only re-runs what has changed.
Check the current directory for an R project (.R files, DESCRIPTION, or .Rproj).
If not an R project, display:
This directory does not appear to be an R project.
Run `/rap-init` to scaffold a new RAP-compliant project first.
Then stop.
If _targets.R already exists in the project root:
R/ for any functions not currently included as targetsThen skip to step 5 (Update DESCRIPTION).
Use Glob to find all .R files in R/. For each file:
^[a-zA-Z_][a-zA-Z0-9_.]* <- function()Read the template from plugins/rap/templates/pipeline/_targets.R.template.
Replace {{PROJECT_NAME}} with the project name.
If the project has custom functions beyond the standard four-stage pattern, customise the _targets.R to include them:
tar_target() callWrite the result to _targets.R in the project root.
If DESCRIPTION exists, check whether targets is listed in Imports: or Suggests:. If not, add it to Suggests::
Suggests:
targets,
tarchetypes
## Pipeline Configured
**File**: `_targets.R`
### Pipeline stages
| Target | Function | Depends on |
|--------|----------|------------|
| raw_data | read_source_data() | — |
| clean_data | process_data() | raw_data |
| analysis_results | analyse_data() | clean_data |
| output | create_output() | analysis_results |
### Running the pipeline
```r
# Run the full pipeline (only re-runs changed stages)
targets::tar_make()
# Visualise the dependency graph
targets::tar_visnetwork()
# Read a cached result
targets::tar_read(analysis_results)
# Check which targets are outdated
targets::tar_outdated()
tar_visnetwork() shows the full dependency graph
### 7. Edge Case Handling
Handle these situations gracefully:
- **No R/ directory**: If `R/` does not exist, display:
No R/ directory found. Run /rap-init to create the standard project structure,
or create R/ and add your pipeline functions before running /rap-pipeline.
- **No functions found in R/**: If R files exist but contain no function definitions (only scripts), warn:
Your R files appear to be scripts rather than functions. {targets} works best with functions. Consider refactoring your scripts into functions: read_data <- function() { ... } Then run /rap-pipeline again.
- **targets not installed**: If the user runs `tar_make()` and targets is not available:
install.packages("targets")
- **Existing _targets.R**: Never overwrite without confirmation. Analyse the current pipeline and suggest improvements instead.
- **DESCRIPTION missing**: Skip the DESCRIPTION update and note that targets should be installed manually.
- **Circular dependencies detected**: If function analysis suggests circular dependencies, warn and suggest restructuring.
### 8. RAP context
End your response with:
> **Build automation** is Silver RAP requirement S1 (minimal manual intervention). The `{targets}` package by Will Landau is the recommended pipeline tool for R, endorsed by the [NHS RAP Community of Practice](https://nhsdigital.github.io/rap-community-of-practice/training_resources/R/R-functions-and-packages/). It replaces manually running numbered scripts with a dependency-aware, cached pipeline.
>
> **Learn more:**
> - [targets manual](https://books.ropensci.org/targets/)
> - [UK Government Analysis Function RAP page](https://analysisfunction.civilservice.gov.uk/support/reproducible-analytical-pipelines/)
> - [Building RAPs with R](https://raps-with-r.dev/)
> - [RAP Companion](https://ukgovdatascience.github.io/rap_companion/)
npx claudepluginhub ivyleavedtoadflax/rapskill --plugin rapScaffolds a new R package with DESCRIPTION, NAMESPACE, testthat, roxygen2, renv, Git, and GitHub Actions CI. Follows usethis conventions. For starting packages from scratch or converting scripts.
Converts repos with ad hoc scripts/notebooks into reproducible Calkit pipelines using calkit init, xr for I/O detection, and YAML stages/environments for Python/R/Julia/etc.