write-roxygen-docs
について
このClaudeスキルは、Rパッケージの包括的なroxygen2ドキュメントを生成します。関数、データセット、クラス、メソッドをカバーし、tidyverseスタイルに従います。標準タグ、相互参照、例、NAMESPACEエントリを自動的に処理します。新規エクスポートのドキュメント作成、内部ヘルパーのドキュメント化、またはドキュメント関連のR CMDチェック通知の修正時にご利用ください。
クイックインストール
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/write-roxygen-docsこのコマンドをClaude Codeにコピー&ペーストしてスキルをインストールします
ドキュメント
Write Roxygen Docs
Complete roxygen2 docs → R fns, datasets, classes.
Use When
- New exported fn → docs
- Internal helper fns
- Pkg datasets
- S3/S4/R6 classes + methods
- Fix doc-related
R CMD checknotes
In
- Required: R fn|dataset|class to doc
- Optional: Related fns → cross-ref (
@family,@seealso) - Optional: Export fn?
Do
Step 1: Fn Docs
Roxygen comments directly above fn:
#' 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 w/ title, desc, @param per param, @return, @examples, @export.
If err: Unsure tag → ?roxygen2::rd_roclet. Common omission @return → CRAN required for all exports.
Step 2: Essential Tags
| Tag | Purpose | Required for export? |
|---|---|---|
#' Title | First line, one sentence | Yes |
#' Description | Paragraph after blank line | Yes |
@param | Parameter documentation | Yes |
@return | Return value description | Yes (CRAN) |
@examples | Usage examples | Strongly recommended |
@export | Add to NAMESPACE | Yes, for public API |
@family | Group related functions | Recommended |
@seealso | Cross-references | Optional |
@keywords internal | Mark as internal | For non-exported docs |
Got: Required tags ID'd. Exports have @param, @return, @examples, @export minimum.
If err: Tag unfamiliar → roxygen2 docs for usage + syntax.
Step 3: Doc 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 has roxygen blocks per dataset w/ @format describing structure + @source for provenance.
If err: R CMD check warns undocumented dataset → ensure quoted string ("city_temperatures") exactly matches obj name saved w/ usethis::use_data().
Step 4: Doc Pkg
Create R/packagename-package.R:
#' @keywords internal
"_PACKAGE"
## usethis namespace: start
## usethis namespace: end
NULL
Got: R/packagename-package.R exists w/ @keywords internal + "_PACKAGE" sentinel. devtools::document() generates man/packagename-package.Rd.
If err: R CMD check reports missing pkg doc page → verify file R/<packagename>-package.R + contains "_PACKAGE".
Step 5: Special Cases
Fns w/ dots in names (S3 methods):
#' @export
#' @rdname process
process.myclass <- function(x, ...) {
# S3 method
}
Reuse docs w/ @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 w/ .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 correctly. @rdname groups S3 methods. @inheritParams reuses params w/o duplicate.
If err: R CMD check warns "no visible binding for global variable" → #' @importFrom rlang .data or utils::globalVariables() last resort.
Step 6: Generate Docs
devtools::document()
Got: man/ updated w/ .Rd files per documented obj. NAMESPACE regenerated w/ correct exports + imports.
If err: Roxygen syntax errs. Common: unclosed brackets in \describe{}, missing #' prefix, invalid tag names. Re-run devtools::document() after fix.
Check
- Every exported fn has
@param,@return,@examples -
devtools::document()runs no errs -
devtools::check()no doc warnings -
@familytags group correctly - Examples run no errs (
devtools::run_examples())
Traps
- Missing
@return: CRAN requires all exports doc return value - Examples need internet/auth: Wrap
\dontrun{}w/ comment why - Slow examples:
\donttest{}for examples that work but slow for CRAN - Markdown in roxygen: Enable
Roxygen: list(markdown = TRUE)in DESCRIPTION - Forget
devtools::document(): Man pages generated, not hand-written
→
create-r-package— initial pkg setup including roxygen configwrite-testthat-tests— test fns you docwrite-vignette— long-form docs beyond fn refsubmit-to-cran— doc requirements for CRAN
GitHub リポジトリ
関連スキル
content-collections
メタこのスキルは、Content Collections(Markdown/MDXファイルを型安全なデータコレクションに変換するTypeScriptファーストのツール)の本番環境でテストされた設定を提供します。Zodバリデーションによる型安全性を実現し、ブログ、ドキュメントサイト、コンテンツ重視のVite + Reactアプリケーション構築時にご利用ください。Viteプラグインの設定、MDXコンパイルから、デプロイ最適化、スキーマバリデーションまで、すべてを網羅しています。
polymarket
メタこのスキルは、開発者がPolymarket予測市場プラットフォームを活用したアプリケーション構築を可能にします。API統合による取引や市場データの取得に加え、WebSocketを介したリアルタイムデータストリーミングにより、ライブ取引や市場活動を監視できます。取引戦略の実装や、ライブ市場更新を処理するツールの作成にご利用ください。
creating-opencode-plugins
メタこのスキルは、開発者がコマンド、ファイル、LSP操作など25種類以上のイベントタイプにフックするOpenCodeプラグインを作成することを支援します。JavaScript/TypeScriptモジュール向けに、プラグイン構造、イベントAPI仕様、および実装パターンを提供します。カスタムイベント駆動ロジックでOpenCode AIアシスタントのライフサイクルをインターセプト、監視、または拡張する必要がある場合にご利用ください。
sglang
メタSGLangは、高性能なLLMサービングフレームワークであり、RadixAttentionプレフィックスキャッシュを活用したJSON、正規表現、エージェントワークフロー向けの高速で構造化された生成を特長とします。特にプレフィックスが繰り返されるタスクにおいて、大幅に高速な推論を実現し、複雑な構造化出力やマルチターン対話に最適です。制約付きデコードが必要な場合や、広範なプレフィックス共有を伴うアプリケーションを構築する場合は、vLLMなどの代替案ではなくSGLangを選択してください。
