write-vignette
关于
This skill helps developers create R package vignettes using R Markdown or Quarto. It covers setup, YAML configuration, code chunk options, and CRAN requirements for building user-facing tutorials. Use it for "Getting Started" guides, documenting multi-function workflows, or meeting CRAN documentation standards.
快速安装
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-vignette在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Write Vignette
Long-form doc vignettes for R pkgs.
Use When
- "Getting Started" tutorial for pkg
- Doc complex workflows across multi fns
- Domain-specific guides (stat methodology)
- CRAN submission requires user-facing docs beyond fn help
In
- Required: R pkg w/ fns to doc
- Required: Vignette title + topic
- Optional: Format (R Markdown or Quarto, default: R Markdown)
- Optional: Vignette needs external data|APIs?
Do
Step 1: Vignette File
usethis::use_vignette("getting-started", title = "Getting Started with packagename")
Got: vignettes/getting-started.Rmd created w/ YAML frontmatter. knitr + rmarkdown added to DESCRIPTION Suggests. vignettes/ dir exists.
If err: usethis::use_vignette() fails → verify cwd is pkg root (contains DESCRIPTION). knitr not installed → install.packages("knitr") first. Manual: create vignettes/ dir + file by hand, ensure YAML has all 3 %\Vignette* entries.
Step 2: Content
---
title: "Getting Started with packagename"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Getting Started with packagename}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
## Introduction
Brief overview of what the package does and who it's for.
## Installation
```r
install.packages("packagename")
library(packagename)
Basic Usage
Walk through the primary workflow:
# Load example data
data <- example_data()
# Process
result <- main_function(data, option = "default")
# Inspect
summary(result)
Advanced Features
Cover optional or advanced functionality.
Conclusion
Summarize and point to other vignettes or resources.
**Got:** Vignette Rmd has Intro, Install, Basic Usage, Advanced, Conclusion. Code uses pkg's exported fns + produces visible out.
**If err:** Examples fail to run → verify pkg installed `devtools::install()`. Examples use pkg name in `library()` (not `devtools::load_all()`). Fns requiring external resources → `eval=FALSE` to show w/o exec.
### Step 3: Code Chunks
Per chunk options:
```r
# Standard evaluated chunk
{r example-basic}
result <- compute_something(1:10)
result
# Show code but don't run (for illustrative purposes)
{r api-example, eval=FALSE}
connect_to_api(key = "your_key_here")
# Run but hide code (show only output)
{r hidden-setup, echo=FALSE}
library(packagename)
# Set global options
{r setup, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.width = 7,
fig.height = 5
)
Got: Setup chunk w/ include=FALSE sets global opts (collapse, comment, fig.width, fig.height). Chunks configured: eval=FALSE for illustrative, echo=FALSE for hidden setup, std for interactive examples.
If err: Chunk opts not taking effect → verify syntax {r chunk-name, option=value} (comma-separated, no quotes around logicals). Setup chunk runs first → place at top.
Step 4: External Deps
Vignettes needing net access|optional pkgs:
{r check-available, include=FALSE}
has_suggested <- requireNamespace("optionalpkg", quietly = TRUE)
{r use-suggested, eval=has_suggested}
optionalpkg::special_function()
Long-running computations → pre-compute + save:
# Save pre-computed results to vignettes/
saveRDS(expensive_result, "vignettes/precomputed.rds")
# Load in vignette
{r load-precomputed}
result <- readRDS("precomputed.rds")
Got: External deps handled gracefully: optional pkgs conditional via requireNamespace(), net-dep code uses eval=FALSE|tryCatch(), expensive computations use pre-computed .rds.
If err: Vignette fails on CRAN due to unavail optional pkgs → wrap w/ conditional var (eval=has_suggested). Pre-computed → ensure .rds in vignettes/ + ref'd via relative path.
Step 5: Build + Test
# Build single vignette
devtools::build_vignettes()
# Build and check (catches vignette issues)
devtools::check()
Got: Vignette builds no errs. HTML out readable.
If err:
- Missing pandoc: Set
RSTUDIO_PANDOCin.Renviron - Pkg not installed:
devtools::install()first - Missing Suggests: Install pkgs in DESCRIPTION Suggests
Step 6: Verify in Pkg Check
devtools::check()
Vignette-related checks: builds correctly, doesn't take too long, no errs.
Got: devtools::check() passes no vignette-related errs|warnings. Vignette builds within CRAN time limits (typically < 60 sec).
If err: Vignette causes check failures → common fixes: add missing Suggests to DESCRIPTION, reduce build time w/ eval=FALSE on slow chunks, ensure VignetteIndexEntry matches title. Run devtools::build_vignettes() separately to isolate.
Check
- Vignette builds no errs via
devtools::build_vignettes() - All code chunks exec correctly
- VignetteIndexEntry matches title
-
devtools::check()passes no vignette warnings - Vignette appears in pkgdown site articles (if applicable)
- Build time reasonable (< 60 sec for CRAN)
Traps
- VignetteIndexEntry mismatch: Index entry in YAML must match what users see in
vignette(package = "pkg") - Missing
vignetteYAML block: All 3%\Vignette*lines required - Vignette too slow for CRAN: Pre-compute results or
eval=FALSEfor expensive ops - Pandoc not found: Ensure
RSTUDIO_PANDOCenv var set - Self-referencing pkg:
library(packagename)notdevtools::load_all()in vignettes
→
write-roxygen-docs— fn-level docs complement vignette tutorialsbuild-pkgdown-site— vignettes appear as articles on pkgdownsubmit-to-cran— CRAN has specific vignette reqscreate-quarto-report— Quarto as alt to R Markdown vignettes
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是理想选择。
