create-r-package
关于
This skill scaffolds a complete R package structure following modern best practices. It sets up essential components like DESCRIPTION, testing with testthat, documentation with roxygen2, dependency management with renv, and CI/CD with GitHub Actions. Use it when starting a new package, converting scripts into a package, or creating a collaborative project skeleton.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/create-r-package在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Create R Package
Scaffold full R pkg w/ modern tools + best practices.
Use When
- New R pkg from scratch
- Loose R scripts → pkg
- Pkg skeleton for collab dev
In
- Required: Pkg name (lowercase, no special except
.) - Required: 1-line desc
- Optional: License (def: MIT)
- Optional: Author (name, email, ORCID)
- Optional: Init renv (def: yes)
Do
Step 1: Skeleton
usethis::create_package("packagename")
setwd("packagename")
Got: Dir w/ DESCRIPTION, NAMESPACE, R/, man/.
If err: Install usethis (install.packages("usethis")). Dir must not exist.
Step 2: DESCRIPTION
Edit w/ accurate metadata:
Package: packagename
Title: What the Package Does (Title Case)
Version: 0.1.0
Authors@R:
person("First", "Last", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0000-0000-0000"))
Description: One paragraph describing what the package does. Must be more
than one sentence. Avoid starting with "This package".
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
URL: https://github.com/username/packagename
BugReports: https://github.com/username/packagename/issues
Got: Valid DESCRIPTION, R CMD check no metadata warns.
If err: Warns → Title Case, Description >1 sentence, Authors@R valid person().
Step 3: Infra
usethis::use_mit_license()
usethis::use_readme_md()
usethis::use_news_md()
usethis::use_testthat(edition = 3)
usethis::use_git()
usethis::use_github_action("check-standard")
Got: LICENSE, README.md, NEWS.md, tests/, .git/, .github/workflows/.
If err: use_*() fail → install missing dep + rerun. .git/ exists → use_git() skips.
Step 4: Dev Config
.Rprofile:
if (file.exists("renv/activate.R")) {
source("renv/activate.R")
}
if (requireNamespace("mcptools", quietly = TRUE)) {
mcptools::mcp_session()
}
.Renviron.example:
RSTUDIO_PANDOC="C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools"
# GITHUB_PAT=your_github_token_here
.Rbuildignore:
^\.Rprofile$
^\.Renviron$
^\.Renviron\.example$
^renv$
^renv\.lock$
^CLAUDE\.md$
^\.github$
^.*\.Rproj$
Got: .Rprofile, .Renviron.example, .Rbuildignore created. Dev files excluded from build.
If err: .Rprofile startup err → check syntax. requireNamespace() guards → prevent fail on missing pkgs.
Step 5: Init renv
renv::init()
Got: renv/ + renv.lock. Local lib active.
If err: Install renv (install.packages("renv")). Hang → check network / options(timeout = 600).
Step 6: Pkg Doc File
R/packagename-package.R:
#' @keywords internal
"_PACKAGE"
## usethis namespace: start
## usethis namespace: end
NULL
Got: File w/ "_PACKAGE" sentinel. devtools::document() → pkg-level help.
If err: Filename = R/<packagename>-package.R. "_PACKAGE" standalone, not in fn.
Step 7: CLAUDE.md
Create CLAUDE.md in root w/ proj-specific instructions for AI.
Got: CLAUDE.md in root w/ conventions + build cmds + arch notes.
If err: Unsure → pkg name, 1-line desc, dev cmds (devtools::check(), devtools::test()), non-obvious conventions.
Check
-
devtools::check()→ 0 err, 0 warn - Struct matches layout
-
.Rprofileloads no err -
renv::status()OK - Git init +
.gitignore - GH Actions workflow present
Traps
- Name conflicts: Check CRAN
available::available("packagename")pre-commit - Missing .Rbuildignore: Dev files (
.Rprofile,.Renviron,renv/) must be excluded - Forgot Encoding: Always
Encoding: UTF-8in DESCRIPTION - RoxygenNote mismatch: Ver in DESCRIPTION = installed roxygen2
Examples
# Minimal creation
usethis::create_package("myanalysis")
# Full setup in one session
usethis::create_package("myanalysis")
usethis::use_mit_license()
usethis::use_testthat(edition = 3)
usethis::use_readme_md()
usethis::use_git()
usethis::use_github_action("check-standard")
renv::init()
→
write-roxygen-docs— doc fnswrite-testthat-tests— add testssetup-github-actions-ci— CI/CD configmanage-renv-dependencies— deps mgmtwrite-claude-md— AI instr
GitHub 仓库
相关推荐技能
content-collections
元Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。
polymarket
元这个Claude Skill为开发者提供完整的Polymarket预测市场开发支持,涵盖API调用、交易执行和市场数据分析。关键特性包括实时WebSocket数据流,可监控实时交易、订单和市场动态。开发者可用它构建预测市场应用、实施交易策略并集成实时市场预测功能。
creating-opencode-plugins
元该Skill帮助开发者创建OpenCode插件,用于接入命令、文件、LSP等25+种事件。它提供了插件结构、事件API规范和JavaScript/TypeScript实现模式,适合需要拦截操作、扩展功能或自定义事件处理的场景。开发者可通过它快速构建响应式模块来增强OpenCode AI助手的能力。
sglang
元SGLang是一个专为LLM设计的高性能推理框架,特别适用于需要结构化输出的场景。它通过RadixAttention前缀缓存技术,在处理JSON、正则表达式、工具调用等具有重复前缀的复杂工作流时,能实现极速生成。如果你正在构建智能体或多轮对话系统,并追求远超vLLM的推理性能,SGLang是理想选择。
