/r-skills:tidymodels-overviewfrom r-skills
Provides tidymodels ecosystem context and workflow guidance (data splitting, recipes, parsnip, workflows, tune, yardstick, stacks). Use when building or troubleshooting ML pipelines in R.
Ships in r-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The tidymodels ecosystem provides a consistent, modular framework for machine learning in R. Understanding the ecosystem context helps when working with any tidymodels pipeline before diving into package-specific details.
Critical: A recipe object is a specification of preprocessing steps. Adding steps like step_normalize() does not transform data immediately. Transformations execute only when:
prep() estimates parameters from training databake() applies the prepped recipe to new data# This does NOT transform data - it creates a plan
rec <- recipe(outcome ~ ., data = train) |>
step_normalize(all_numeric_predictors())
# This estimates parameters (means, sds) from training data
prepped <- prep(rec, training = train)
# This applies transformations to new data
processed <- bake(prepped, new_data = test)
Follow this standard workflow for modeling projects:
Allocate data to training, validation, and test sets before any modeling:
set.seed(123)
data_split <- initial_split(data, prop = 0.8, strata = outcome)
train_data <- training(data_split)
test_data <- testing(data_split)
# For iterative evaluation during development
resamples <- vfold_cv(train_data, v = 10)
Define feature engineering as a recipe specification:
rec_spec <- recipe(outcome ~ ., data = train_data) |>
step_normalize(all_numeric_predictors()) |>
step_dummy(all_factor_predictors()) |>
step_zv(all_predictors())
Use tidyselect helpers for column selection:
all_predictors(), all_outcomes() - by roleall_numeric_predictors(), all_nominal_predictors() - by type and rolehas_role(), has_type() - explicit queriesDefine the model type, engine, and mode separately from fitting:
model_spec <- rand_forest(mtry = tune(), trees = 1000) |>
set_engine("ranger") |>
set_mode("regression")
Combine preprocessing and model into a single object:
wflow <- workflow() |>
add_recipe(rec_spec) |>
add_model(model_spec)
Use resampling or validation sets to assess performance:
# Define metrics
metrics <- metric_set(rmse, rsq, mae)
# Tune hyperparameters
tuned <- tune_grid(
wflow,
resamples = resamples,
grid = 10,
metrics = metrics
)
# Select best parameters
best_params <- select_best(tuned, metric = "rmse")
Finalize the workflow and fit to full training data:
final_wflow <- finalize_workflow(wflow, best_params)
final_fit <- last_fit(final_wflow, split = data_split)
# Extract test set metrics
collect_metrics(final_fit)
| Package | Purpose | Key Functions |
|---|---|---|
| rsample | Data splitting and resampling | initial_split(), vfold_cv(), bootstraps() |
| recipes | Preprocessing specification | recipe(), step_*(), prep(), bake() |
| parsnip | Model specification | Model functions, set_engine(), set_mode() |
| workflows | Bundle recipe + model | workflow(), add_recipe(), add_model() |
| tune | Hyperparameter optimization | tune_grid(), tune_bayes(), select_best() |
| yardstick | Performance metrics | metric_set(), rmse(), accuracy() |
| workflowsets | Compare multiple pipelines | workflow_set(), workflow_map() |
| stacks | Model ensembling | stacks(), add_candidates(), blend_predictions() |
| hardhat | Internal infrastructure | mold(), forge(), blueprints |
Never directly modify tidymodels object internals. Always use provided functions:
# WRONG - directly modifying internals
recipe_obj$steps[[1]]$means <- new_means
# CORRECT - use proper functions
rec <- recipe(...) |>
step_normalize(...) |>
prep()
Avoid constructing variable lists manually:
# WRONG - manual string matching
numeric_cols <- names(data)[sapply(data, is.numeric)]
rec |> step_normalize(all_of(numeric_cols))
# CORRECT - use tidyselect helpers
rec |> step_normalize(all_numeric_predictors())
Custom roles are required at bake() time by default. When using step_rm() with custom roles, update requirements:
rec <- recipe(...) |>
update_role(id_column, new_role = "id") |>
update_role_requirements("id", bake = FALSE) |>
step_rm(has_role("id"))
All workflows in a workflow_set must predict the same outcome variable. For different outcomes, create separate workflow sets.
save_pred = TRUE, save_workflow = TRUE)For detailed information, consult:
references/packages.md - Detailed package documentation including object structures, creation processes, and deep knowledge linksreferences/common-problems.md - Common pitfalls when working with tidymodels and how to avoid themWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
tidymodels, r-machine-learning, workflow-guide, recipe, parsnip, tune
9 skills in this plugin
/designing-tidy-r-functionsUse when designing R function APIs, reviewing R code for design issues, writing functions for R packages, or evaluating argument ordering and naming decisions. Does NOT cover: style/linting, error handling (rlang-conditions), CLI output (r-lib:cli), testing (testing-r-packages), CRAN compliance (cran-extrachecks).
/ggplot2Use when working with R ggplot2 package, especially ggplot2 4.0+ features. Covers S7 migration (@ property access), theme defaults with ink/paper/accent, element_geom(), from_theme(), theme shortcuts (theme_sub_*), palette themes, labels with dictionary/attributes, discrete scale improvements (palette, continuous.limits, minor_breaks, sec.axis), position aesthetics (nudge_x/nudge_y, order), facet_wrap dir/space/layout, boxplot/violin/label styling, stat_manual(), stat_connect(), coord reversal./hardhatUse when creating an R modeling package that needs standardized preprocessing for formula, data frame, matrix, and recipe interfaces. Covers: mold() for training data preprocessing, forge() for prediction data validation, blueprints, model constructors, spruce functions for output formatting.
/metaprogrammingUse when writing R code that manipulates expressions, builds code programmatically, or needs to understand rlang's defuse/inject mechanics. Covers: defusing with expr()/enquo()/enquos(), quosure environment tracking, injection with !!/!!!/{{, symbol construction with sym()/syms(). Does NOT cover: data-mask programming patterns (tidy-evaluation), error handling (rlang-conditions), function design (designing-tidy-r-functions).
/rlang-conditionsUse when developing R packages that need to handle errors, warnings, and conditions properly. Covers: (1) cli_abort/cli_warn/cli_inform for throwing conditions with formatting, (2) Error call context with caller_env() and caller_arg(), (3) Input validation helpers that report the right function, (4) Error chaining with try_fetch() and parent argument, (5) Testing error conditions with testthat snapshots.
/r-languageserverUse when navigating, reading, or refactoring R code: finding where an R function is defined or called, tracing call hierarchies, finding a function's callers before changing it (impact analysis), looking up a function's documentation, or interpreting the lint diagnostics that appear after editing R files. Prefer the LSP over text search for these — it resolves symbols semantically and avoids false matches in comments, strings, and docstrings.
npx claudepluginhub jsperger/llm-r-skills --plugin r-skillsOther plugins' skills for the same job