create-r-package
关于
This Claude Skill scaffolds a complete, production-ready R package structure from scratch, following usethis conventions and tidyverse style. It automatically generates essential files for DESCRIPTION, documentation, testing, dependency management (renv), version control, and CI/CD with GitHub Actions. Use it to initialize a new package, convert loose scripts into a structured project, or create a collaborative package 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 fully configured R package with modern tooling and best practices.
When Use
- Starting new R package from scratch
- Converting loose R scripts into package
- Setting up package skeleton for collaborative development
Inputs
- Required: Package name (lowercase, no special chars except
.) - Required: One-line description of package purpose
- Optional: License type (default: MIT)
- Optional: Author info (name, email, ORCID)
- Optional: Whether to init renv (default: yes)
Steps
Step 1: Create Package Skeleton
usethis::create_package("packagename")
setwd("packagename")
Got: Directory created with DESCRIPTION, NAMESPACE, R/, man/ subdirectories.
If fail: Confirm usethis installed (install.packages("usethis")). Check directory does not already exist.
Step 2: Configure DESCRIPTION
Edit DESCRIPTION with 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 passing R CMD check with no metadata warnings.
If fail: R CMD check warns about DESCRIPTION fields? Verify Title in Title Case, Description more than one sentence, Authors@R uses valid person() syntax.
Step 3: Set Up Infrastructure
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/ directory, .git/ initialized, .github/workflows/ created.
If fail: Any usethis::use_*() function fails? Install missing dependency, rerun. .git/ already exists? use_git() skips init.
Step 4: Create Development Configuration
Create .Rprofile:
if (file.exists("renv/activate.R")) {
source("renv/activate.R")
}
if (requireNamespace("mcptools", quietly = TRUE)) {
mcptools::mcp_session()
}
Create .Renviron.example:
RSTUDIO_PANDOC="C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools"
# GITHUB_PAT=your_github_token_here
Create .Rbuildignore entries:
^\.Rprofile$
^\.Renviron$
^\.Renviron\.example$
^renv$
^renv\.lock$
^CLAUDE\.md$
^\.github$
^.*\.Rproj$
Got: .Rprofile, .Renviron.example, .Rbuildignore created. Development files dropped from built package.
If fail: .Rprofile causes startup errors? Check syntax. Confirm requireNamespace() guards stop failures when optional packages missing.
Step 5: Initialize renv
renv::init()
Got: renv/ directory and renv.lock created. Project-local library active.
If fail: Install renv with install.packages("renv"). renv hangs during init? Check network. Set options(timeout = 600).
Step 6: Create Package Documentation File
Create R/packagename-package.R:
#' @keywords internal
"_PACKAGE"
## usethis namespace: start
## usethis namespace: end
NULL
Got: R/packagename-package.R exists with "_PACKAGE" sentinel. Running devtools::document() generates package-level help.
If fail: Confirm filename matches pattern R/<packagename>-package.R. "_PACKAGE" string must be standalone expression, not inside function.
Step 7: Create CLAUDE.md
Create CLAUDE.md in project root with project-specific instructions for AI assistants.
Got: CLAUDE.md exists in project root with project-specific editing conventions, build commands, architecture notes.
If fail: Unsure what to include? Start with package name, one-line description, common dev commands (devtools::check(), devtools::test()), any non-obvious conventions.
Checks
-
devtools::check()returns 0 errors, 0 warnings - Package structure matches expected layout
-
.Rprofileloads without errors -
renv::status()shows no issues - Git repo initialized with right
.gitignore - GitHub Actions workflow file present
Pitfalls
- Package name conflicts: Check CRAN with
available::available("packagename")before committing to a name - Missing .Rbuildignore entries: Development files (
.Rprofile,.Renviron,renv/) must drop from built package - Forgetting Encoding: Always include
Encoding: UTF-8in DESCRIPTION - RoxygenNote mismatch: Version in DESCRIPTION must match 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()
See Also
write-roxygen-docs- document functions you createwrite-testthat-tests- add tests for packagesetup-github-actions-ci- detailed CI/CD configurationmanage-renv-dependencies- manage package dependencieswrite-claude-md- create effective AI assistant instructions
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是理想选择。
