Back to Skills

create-r-package

pjt222
Updated 6 days ago
16 views
17
2
17
View on GitHub
Metaaitesting

About

This Claude Skill scaffolds a complete, production-ready R package structure following usethis conventions and tidyverse style. It generates essential files including DESCRIPTION, NAMESPACE, testing with testthat, documentation with roxygen2, dependency management with renv, and CI/CD with GitHub Actions. Use it when starting a new package from scratch, converting loose scripts into a structured package, or setting up a collaborative project skeleton.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/create-r-package

Copy and paste this command in Claude Code to install this skill

Documentation

造 R 包

架含新具與佳實之全設 R 包。

  • 自零始新 R 包
  • 化散 R 本為包
  • 為合作發立包骨

  • :包名(小寫、特符僅 .
  • :一行包目述
  • :執照(默:MIT)
  • :作者(名、郵、ORCID)
  • :是否初 renv(默:是)

一:造包骨

usethis::create_package("packagename")
setwd("packagename")

得: 目建、含 DESCRIPTIONNAMESPACER/man/ 子目。

敗: 保 usethis 裝(install.packages("usethis"))。察目未存。

二:設 DESCRIPTION

DESCRIPTION 含正備:

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

得: 有效 DESCRIPTION 通 R CMD check 無備警。

敗: R CMD check 警 DESCRIPTION 欄→驗 Title 為 Title Case、Description 過一句、Authors@R 用有效 person() 文。

三:設基建

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")

得: LICENSE、README.md、NEWS.md、tests/ 目、.git/ 初、.github/workflows/ 建。

敗: usethis::use_*() 敗→裝缺依重行。.git/ 已存→use_git() 略初。

四:建發設

.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$

得: .Rprofile.Renviron.example.Rbuildignore 建。發檔除於構包。

敗: .Rprofile 啟誤→察文法。保 requireNamespace() 守防選包缺時敗。

五:初 renv

renv::init()

得: renv/ 目與 renv.lock 建。案地庫活。

敗: install.packages("renv") 裝 renv。初懸→察網或 options(timeout = 600)

六:建包備檔

R/packagename-package.R

#' @keywords internal
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL

得: R/packagename-package.R 存含 "_PACKAGE" 哨。devtools::document() 生包級助。

敗: 保檔名合 R/<packagename>-package.R 模。"_PACKAGE" 須為獨表、非於函內。

七:建 CLAUDE.md

於案根建 CLAUDE.md 含 AI 助手之案專令。

得: CLAUDE.md 存於案根含案專編規、構令、架注。

敗: 疑何含→始於包名、一行述、常發令(devtools::check()devtools::test())、任不明規。

  • devtools::check() 返零誤零警
  • 包構合期
  • .Rprofile 載無誤
  • renv::status() 顯無問
  • Git 庫初含合 .gitignore
  • GitHub Actions 流檔存

  • 包名衝:委名前以 available::available("packagename") 察 CRAN
  • 缺 .Rbuildignore 項:發檔(.Rprofile.Renvironrenv/)須除於構包
  • 忘 Encoding:DESCRIPTION 恆含 Encoding: UTF-8
  • RoxygenNote 不合:DESCRIPTION 中版須合裝之 roxygen2

# 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 - 備所造函
  • write-testthat-tests - 為包加試
  • setup-github-actions-ci - 備 CI/CD 設細
  • manage-renv-dependencies - 理包依
  • write-claude-md - 造效 AI 助令

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan-ultra/skills/create-r-package
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

polymarket

Meta

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

View skill

creating-opencode-plugins

Meta

This skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill