返回技能列表

write-roxygen-docs

pjt222
更新于 2 days ago
8 次查看
17
2
17
在 GitHub 上查看
worddata

关于

This Claude Skill generates comprehensive roxygen2 documentation for R packages, covering functions, datasets, classes, and methods while following tidyverse style. It handles standard tags, cross-references, examples, and NAMESPACE entries to ensure proper package structure. Use it when documenting new exports, internal helpers, or fixing R CMD check notes.

快速安装

Claude Code

推荐
主要方式
npx skills add pjt222/agent-almanac -a claude-code
插件命令备选方式
/plugin add https://github.com/pjt222/agent-almanac
Git 克隆备选方式
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/write-roxygen-docs

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

Write Roxygen Documentation

Create complete roxygen2 documentation for R package functions, datasets, classes.

When Use

  • Adding documentation to new exported function
  • Documenting internal helper functions
  • Documenting package datasets
  • Documenting S3/S4/R6 classes and methods
  • Fixing documentation-related R CMD check notes

Inputs

  • Required: R function, dataset, or class to document
  • Optional: Related functions for cross-referencing (@family, @seealso)
  • Optional: Whether function should be exported

Steps

Step 1: Write Function Documentation

Place roxygen comments directly above function:

#' Compute the weighted mean of a numeric vector
#'
#' Calculates the arithmetic mean of `x` weighted by `w`. Missing values
#' in either `x` or `w` are handled according to the `na.rm` parameter.
#'
#' @param x A numeric vector of values.
#' @param w A numeric vector of weights, same length as `x`.
#' @param na.rm Logical. Should missing values be removed? Default `FALSE`.
#'
#' @return A single numeric value representing the weighted mean.
#'
#' @examples
#' weighted_mean(1:5, rep(1, 5))
#' weighted_mean(c(1, 2, NA, 4), c(1, 1, 1, 1), na.rm = TRUE)
#'
#' @export
#' @family summary functions
#' @seealso [stats::weighted.mean()] for the base R equivalent
weighted_mean <- function(x, w, na.rm = FALSE) {
  # implementation
}

Got: Complete roxygen block with title, description, @param for each parameter, @return, @examples, @export.

If err: Unsure about a tag? Check ?roxygen2::rd_roclet. Common omission is @return. Required by CRAN for all exported functions.

Step 2: Essential Tags Reference

TagPurposeRequired for export?
#' TitleFirst line, one sentenceYes
#' DescriptionParagraph after blank lineYes
@paramParameter documentationYes
@returnReturn value descriptionYes (CRAN)
@examplesUsage examplesStrongly recommended
@exportAdd to NAMESPACEYes, for public API
@familyGroup related functionsRecommended
@seealsoCross-referencesOptional
@keywords internalMark as internalFor non-exported docs

Got: All required tags for function type identified. Exported functions have @param, @return, @examples, @export at minimum.

If err: Tag unfamiliar? Consult roxygen2 documentation for usage and syntax.

Step 3: Document Datasets

Create R/data.R:

#' Example dataset of city temperatures
#'
#' A dataset containing daily temperature readings for major cities.
#'
#' @format A data frame with 365 rows and 4 variables:
#' \describe{
#'   \item{date}{Date of observation}
#'   \item{city}{City name}
#'   \item{temp_c}{Temperature in Celsius}
#'   \item{humidity}{Relative humidity percentage}
#' }
#' @source \url{https://example.com/data}
"city_temperatures"

Got: R/data.R contains roxygen blocks for each dataset with @format describing structure and @source providing data provenance.

If err: R CMD check warns about undocumented datasets? Ensure quoted string (e.g., "city_temperatures") exactly matches object name saved with usethis::use_data().

Step 4: Document Package

Create R/packagename-package.R:

#' @keywords internal
"_PACKAGE"

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

Got: R/packagename-package.R exists with @keywords internal and "_PACKAGE" sentinel. Running devtools::document() generates man/packagename-package.Rd.

If err: R CMD check reports missing package documentation page? Verify file named R/<packagename>-package.R and contains "_PACKAGE" string.

Step 5: Handle Special Cases

Functions with dots in names (S3 methods):

#' @export
#' @rdname process
process.myclass <- function(x, ...) {
  # S3 method
}

Reusing documentation with @inheritParams:

#' @inheritParams weighted_mean
#' @param trim Fraction of observations to trim.
trimmed_mean <- function(x, w, na.rm = FALSE, trim = 0.1) {
  # implementation
}

No visible binding fix using .data pronoun:

#' @importFrom rlang .data
my_function <- function(df) {
  dplyr::filter(df, .data$column > 5)
}

Got: Special cases (S3 methods, inherited params, .data pronoun) documented correct. @rdname groups S3 methods together. @inheritParams reuses parameter docs without duplication.

If err: R CMD check warns about "no visible binding for global variable"? Add #' @importFrom rlang .data or use utils::globalVariables() as last resort.

Step 6: Generate Documentation

devtools::document()

Got: man/ directory updated with .Rd files for each documented object. NAMESPACE regenerated with correct exports and imports.

If err: Check roxygen syntax errors. Common issues: unclosed brackets in \describe{}, missing #' prefix on line, or invalid tag names. Run devtools::document() again after fixing.

Check

  • Every exported function has @param, @return, @examples
  • devtools::document() runs without errors
  • devtools::check() shows no documentation warnings
  • @family tags group related functions correct
  • Examples run without errors (test with devtools::run_examples())

Pitfalls

  • Missing @return: CRAN requires all exported functions to document their return value
  • Examples that need internet/auth: Wrap in \dontrun{} with comment explaining why
  • Slow examples: Use \donttest{} for examples that work but take too long for CRAN
  • Markdown in roxygen: Enable with Roxygen: list(markdown = TRUE) in DESCRIPTION
  • Forget to run devtools::document(): Man pages generated, not hand-written

See Also

  • create-r-package - initial package setup including roxygen configuration
  • write-testthat-tests - test functions you document
  • write-vignette - long-form documentation beyond function reference
  • submit-to-cran - documentation requirements for CRAN

GitHub 仓库

pjt222/agent-almanac
路径: i18n/caveman/skills/write-roxygen-docs
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

相关推荐技能

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是理想选择。

查看技能