/r-package-skills:r-collapsefrom r-package-skills
Provides fast grouped/weighted statistics in R using the collapse package. 50-100x faster than dplyr for large datasets (>100k rows). Covers aggregation, panel data, and time series operations.
Ships in r-package-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.
collapse provides C/C++-based high-performance grouped and weighted statistics. 50-100x faster than dplyr for grouped operations, matches data.table speed while working with any data frame type (tibbles, data.tables, xts).
Core principle: Fast aggregation, transformation, and panel data operations through vectorized C code.
Read references/API.md before writing code.
references/API.md - Complete function referencereferences/collapse-for-tidyverse-users.md - Migration guide and patternsreferences/collapse-documentation.md - Core concepts and usagereferences/collapse-and-sf.md - Working with spatial datareferences/collapse-object-handling.md - Data structure handlingUse collapse when:
Don't use:
vs Alternatives:
| Scenario | Use This |
|---|---|
| Large grouped stats | collapse |
| Weighted computations | collapse |
| sf manipulation | dplyr |
| Reference semantics | data.table |
| Complex joins | data.table |
| Arbitrary group functions | dplyr |
| Task | Function/Example |
|---|---|
| Grouped stats | fmean(), fsum(), fsd(), fmedian() |
| Aggregation | collap(df, ~ by, list(fmean, fsd)) |
| Transform | ftransform(), fmutate() |
| Selection | fselect(), fsubset() (~100x faster) |
| Time series | flag(), fdiff(), fgrowth() |
| Panel data | fwithin(), fbetween(), qsu() |
| Grouping | fgroup_by(), GRP() |
library(collapse)
# Basic: grouped mean (50-100x faster than dplyr)
data |> fgroup_by(category) |> fmean()
# Weighted aggregation
data |> fgroup_by(region) |> fmean(w = weight_col)
# Multiple stats at once
collap(data, ~ category, list(fmean, fsd, fmedian))
# TRA transformations (key differentiator - single C pass)
data |> fgroup_by(id) |> fmean(TRA = "-") # Demean: subtract group mean
data |> fgroup_by(id) |> fsd(TRA = "/") # Scale: divide by group SD
data |> fgroup_by(id) |> fmean(TRA = "fill") # Fill: replace NA with group mean
# See references/API.md for full TRA options ("-", "/", "fill", "-+", "replace")
| Mistake | Fix |
|---|---|
Using group_by() with collapse functions | Use fgroup_by() or pass g = GRP(groupvar) |
collap() applies to ALL numeric columns | Explicitly select columns before calling |
Expecting na.rm = FALSE default | collapse defaults to na.rm = TRUE |
fwithin()/fbetween() collapse rows | They return same # rows (centered/group means) |
| Global options affect behavior | Set arguments explicitly in package code |
Ignoring sort = FALSE speedup | Add sort = FALSE when order doesn't matter (3x faster) |
See references/ for API reference, vignette content (tidyverse comparison, sf integration, object handling, development guidelines), and panel data patterns.
Validator: lib/r-validators/numerical-validator.R
Resources: Docs
references/API.md (opens in a new tab)references/advanced.md (opens in a new tab)references/collapse-and-sf.md (opens in a new tab)references/collapse-documentation.md (opens in a new tab)references/collapse-for-tidyverse-users.md (opens in a new tab)references/collapse-object-handling.md (opens in a new tab)references/developing-with-collapse.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub arthurgailes/r-package-skills --plugin r-package-skills14 skills in this plugin
/r-aiUse when code loads ellmer, btw, mcptools, ragnar, or vitals, building LLM-powered R applications, implementing RAG workflows, or choosing between R AI packages (meta-skill for ellmer/btw/mcptools/ragnar/vitals)/r-btwUse when code loads or uses btw (library(btw), btw::), providing R session context to LLMs, registering tools for ellmer chat, or copying R object descriptions to clipboard/r-duckplyrUse when code loads or uses duckplyr (library(duckplyr), duckplyr::), processing large datasets with dplyr syntax, working with Parquet files in R, or needing lazy evaluation for bigger-than-memory data/r-duckspatialUse when code loads or uses duckspatial (library(duckspatial), duckspatial::), performing spatial joins or areal interpolation on large vector datasets in R, or needing faster spatial operations than sf/r-ellmerUse when code loads or uses ellmer (library(ellmer), chat_openai, chat_claude, chat_ollama), chatting with LLMs from R, building chatbots, or extracting structured data from text with LLMs/r-flextableUse when code loads or uses flextable (library(flextable), flextable::), creating formatted tables for Word (.docx), PowerPoint (.pptx), HTML, or PDF in R, or needing merged cells and conditional formattingOther plugins' skills for the same job