重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
npx skills add https://github.com/posit-dev/skills --skill cran-extrachecks帮助 R 包开发者系统性地检查 CRAN 提交准备情况,涵盖 CRAN 审阅者强制执行但 devtools::check() 无法捕获的常见临时性要求。
系统性地处理以下项目:
usethis::use_news_md()usethis::use_cran_comments()install.packages("pkgname"))。
* 检查是否包含相对链接。这在 GitHub 上有效,但会被 CRAN 标记。请使用完整的包文档 URL 或移除链接。
* README 是否清晰地解释了包的用途和功能?
* : 如果存在 README.Rmd, README.Rmd(README.md 会被覆盖),然后运行 重新渲染 README.md广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
devtools::build_readme()Title: 和 Description: 字段(见下文详细指南)@return 和 @examples(见下文详细指南)Authors@R: 是否包含角色为 [cph] 的版权持有者urlchecker::url_check() 并修复任何问题返回值文档(严格执行)
CRAN 现在严格要求所有导出的函数都必须有 @return 文档。使用 roxygen2 标签 @return 来记录函数的返回值。
@keywords internal 的函数也是必需的@return None 或类似内容示例:
# 缺少 @return - 将被拒绝
#' 计算总和
#' @export
my_sum <- function(x, y) {
x + y
}
# 正确 - 包含 @return
#' 计算总和
#' @param x 第一个数字
#' @param y 第二个数字
#' @return 一个数值
#' @export
my_sum <- function(x, y) {
x + y
}
# 对于没有返回值的函数
#' 打印消息
#' @param msg 要打印的消息
#' @return 无,调用是为了副作用
#' @export
print_msg <- function(msg) {
cat(msg, "\n")
}
导出函数的示例
如果你的导出函数有有意义的返回值,几乎肯定需要一个 @examples 部分。使用 roxygen2 标签 @examples。
@keywords internal 的函数也是必需的未导出函数的示例
如果你为未导出的函数编写 roxygen 示例,你必须:
::: 符号调用它们:pkg:::my_fun()@noRd 标签来抑制 .Rd 文件的创建谨慎使用 \dontrun{}
\dontrun{} 应仅在示例确实无法执行时使用(例如,缺少额外软件、API 密钥等)。
try() 中if () 块的自定义谓词(例如 googlesheets4::sheets_has_token())interactive() 作为条件\donttest{}切勿在示例中注释掉代码
# 错误 - 将被拒绝
#' @examples
#' # my_function(x) # 不要这样做!
CRAN 的指导原则:"示例中的示例/代码行不应被注释掉。理想情况下,找到可以定期执行和检查的玩具示例。"
使用建议包来保护示例
对于需要建议包的整个示例部分,使用 @examplesIf:
#' @examplesIf rlang::is_installed("dplyr")
#' library(dplyr)
#' my_data %>% my_function()
对于示例中的单个代码块:
#' @examples
#' if (rlang::is_installed("dplyr")) {
#' library(dplyr)
#' my_data %>% my_function()
#' }
CRAN 强制执行严格的标题要求:
使用标题大小写
除冠词如 'a'、'the' 外,所有单词首字母大写。使用 tools::toTitleCase() 帮助格式化。
避免冗余
常被标记的短语:
示例:
# 错误
Title: A Toolkit for the Construction of Modeling Packages for R
# 正确
Title: Construct Modeling Packages
# 错误
Title: Command Argument Parsing for R
# 正确
Title: Command Argument Parsing
引用软件/包名称
将所有软件和 R 包名称放在单引号中:
# 正确
Title: Interface to 'Tiingo' Stock Price API
长度限制
保持标题在 65 个字符以内。
切勿以禁止的短语开头
CRAN 将拒绝以以下内容开头的描述:
"This package"
包名称
"Functions for"
Description: This package provides functions for rendering slides. Description: Functions for rendering slides to different formats.
Description: Render slides to different formats including HTML and PDF.
扩展至 3-4 句话
单句描述是不够的。提供更广泛的描述,包括:
包的功能
它可能有用之处
它帮助解决的问题类型
Description: Render slides to different formats.
Description: Render slides to different formats including HTML and PDF. Supports custom themes and progressive disclosure patterns. Integrates with 'reveal.js' for interactive presentations. Designed for technical presentations and teaching materials.
引用软件名称,而非函数名
# 错误
Description: Uses 'case_when()' to process data.
# 正确
Description: Uses case_when() to process data with 'dplyr'.
软件、包和 API 名称使用单引号(包括 'R')。函数名不使用。
扩展所有首字母缩写词
所有首字母缩写词在首次提及时必须完全展开:
# 错误
Description: Implements X-SAMPA processing.
# 正确
Description: Implements Extended Speech Assessment Methods Phonetic
Alphabet (X-SAMPA) processing.
仅出版物标题使用双引号
仅对出版物标题使用双引号,不对短语或强调使用:
# 错误
Description: Handles dates like "the first Monday of December".
# 正确
Description: Handles dates like the first Monday of December.
所有 URL 必须使用 HTTPS
CRAN 要求所有 URL 使用 https:// 协议。HTTP 链接将被拒绝。
# 错误
URL: http://paleobiodb.org/
# 正确
URL: https://paleobiodb.org/
无重定向 URL
CRAN 拒绝重定向到其他位置的 URL。拒绝示例:
Found the following (possibly) invalid URLs:
URL: https://h3geo.org/docs/core-library/coordsystems#faceijk-coordinates
(moved to https://h3geo.org/docs/core-library/coordsystems/)
使用 urlchecker 包
# 查找重定向 URL
urlchecker::url_check()
# 自动更新到最终目的地
urlchecker::url_update()
忽略发布后才会存在的 URL
一些当前无法解析的 URL 在包发布到 CRAN 后将存在。这些不应更改:
https://cran.r-project.org/package=pkgname)https://www.r-pkg.org/badges/version/pkgname)https://cranchecks.info/badges/pkgname)当 urlchecker::url_check() 标记这些 URL 时,保持原样。它们是期望的 URL,一旦包在 CRAN 上就会生效。
检查无效的文件 URI
README 中的相对链接在包构建后必须存在。常见问题:
Found the following (possibly) invalid file URI:
URI: CODE_OF_CONDUCT.md
From: README.md
当文件在 .Rbuildignore 中时会发生此问题。解决方案:
.Rbuildignore 中移除文件usethis::use_code_of_conduct(),它会生成不带相对链接的部分版权持有者角色
始终在作者字段中添加 [cph] 角色,即使你是唯一作者:
# 必需
Authors@R: person("John", "Doe", role = c("aut", "cre", "cph"))
Posit 支持的包
对于属于 Posit 相关 GitHub 组织(posit-dev、rstudio、r-lib、tidyverse、tidymodels)或由拥有 @posit.co 电子邮件地址的人维护的包,请包含 Posit Software, PBC 作为版权持有者和资助者:
Authors@R: c(
person("Jane", "Doe", role = c("aut", "cre"),
email = "jane.doe@posit.co"),
person("Posit Software, PBC", role = c("cph", "fnd"),
comment = c(ROR = "03wc8by49"))
)
LICENSE 年份
将 LICENSE 年份更新为当前提交年份:
# 如果 LICENSE 显示 2024 年但提交于 2026 年
# 更新:2024 → 2026
方法参考文献
CRAN 可能会询问:
如果有描述你包中方法的参考文献,请在描述字段中添加这些...
如果没有参考文献,请回复邮件解释这一点。考虑在 cran-comments.md 中添加预防性说明:
## 方法参考文献
没有描述此包中方法的已发表参考文献。
该包实现了用于 [简要描述] 的原创功能。
系统性地处理这些文件:
@return、@examples、@examplesIf、@noRd)devtools::build_readme()DESCRIPTION 标题:
# 之前
Title: A Toolkit for the Construction of Modeling Packages for R
# 之后
Title: Construct Modeling Packages
DESCRIPTION 描述:
# 之前
Description: This package provides functions for rendering slides.
# 之后
Description: Render slides to different formats including HTML and PDF.
Supports custom themes and progressive disclosure. Integrates with
'reveal.js' for interactive presentations.
函数文档:
# 之前 - 缺少 @return
#' 计算总和
#' @param x 数值
#' @export
calc_total <- function(x) sum(x)
# 之后 - 完整的文档
#' 计算总和
#' @param x 要求和的数据值
#' @return 表示总和的数值
#' @examples
#' calc_total(1:10)
#' @export
calc_total <- function(x) sum(x)
tools::toTitleCase() - 使用正确的大小写格式化标题urlchecker::url_check() - 查找有问题的 URLurlchecker::url_update() - 修复重定向的 URLusethis::use_news_md() - 创建 NEWS.mdusethis::use_cran_comments() - 创建 cran-comments.mddevtools::build_readme() - 从 README.Rmd 重新渲染 README.mdusethis::use_code_of_conduct() - 添加不带相对链接的行为准则usethis::use_build_ignore() - 在 R 包构建中忽略文件usethis::use_package() - 向 DESCRIPTION 添加包依赖usethis::use_tidy_description() - 整理 DESCRIPTION 格式在提交前使用此检查清单确保没有遗漏任何事项:
NEWS.md 存在并记录了此版本的更改cran-comments.md 存在并包含提交说明devtools::build_readme()install.packages("pkgname"))Title: 使用标题大小写Title: 没有冗余短语("A Toolkit for"、"Tools for"、"for R")Title: 将所有软件/包名称用单引号引用Title: 少于 65 个字符Description: 不以 "This package"、包名称或 "Functions for" 开头Description: 是 3-4 句话,解释了目的和实用性Description: 引用软件/包/API 名称(包括 'R')但不引用函数名Description: 在首次提及时扩展所有首字母缩写词Description: 仅对出版物标题使用双引号Authors@R: 包含具有 [cph] 角色的版权持有者person("Posit Software, PBC", role = c("cph", "fnd"), comment = c(ROR = "03wc8by49"))@return 文档@examples\dontrun{},除非确实必要@examplesIf 或 if 保护::: 符号或 @noRdurlchecker::url_check().Rbuildignore 文件的相对链接cran-comments.md 中添加预防性说明每周安装次数
89
代码仓库
GitHub 星标数
205
首次出现
2026年2月10日
安全审计
安装于
opencode82
github-copilot81
claude-code79
codex79
gemini-cli79
amp78
Help R package developers prepare packages for CRAN submission by systematically checking for common ad-hoc requirements that CRAN reviewers enforce but devtools::check() doesn't catch.
Work through these items systematically:
usethis::use_news_md() if not already presentusethis::use_cran_comments() if not already presentinstall.packages("pkgname")).devtools::build_readme() to re-render README.mdTitle: and Description: fields (see detailed guidance below)@return and @examples (see detailed guidance below)Authors@R: includes a copyright holder with role [cph]urlchecker::url_check() and fix any issuesReturn Value Documentation (Strictly Enforced)
CRAN now strictly requires @return documentation for all exported functions. Use the roxygen2 tag @return to document what the function returns.
@keywords internal@return None or similarExample:
# Missing @return - WILL BE REJECTED
#' Calculate sum
#' @export
my_sum <- function(x, y) {
x + y
}
# Correct - includes @return
#' Calculate sum
#' @param x First number
#' @param y Second number
#' @return A numeric value
#' @export
my_sum <- function(x, y) {
x + y
}
# For functions with no return value
#' Print message
#' @param msg Message to print
#' @return None, called for side effects
#' @export
print_msg <- function(msg) {
cat(msg, "\n")
}
Examples for Exported Functions
If your exported function has a meaningful return value, it will almost definitely require an @examples section. Use the roxygen2 tag @examples.
@keywords internalUn-exported Functions with Examples
If you write roxygen examples for un-exported functions, you must either:
::: notation: pkg:::my_fun()@noRd tag to suppress .Rd file creationUsing\dontrun{} Sparingly
\dontrun{} should only be used if the example really cannot be executed (e.g., missing additional software, API keys, etc.).
try() insteadgooglesheets4::sheets_has_token()) with if () blocksinteractive() can be used as the condition\donttest{}Never Comment Out Code in Examples
# BAD - Will be rejected
#' @examples
#' # my_function(x) # Don't do this!
CRAN's guidance: "Examples/code lines in examples should never be commented out. Ideally find toy examples that can be regularly executed and checked."
Guarding Examples with Suggested Packages
Use @examplesIf for entire example sections requiring suggested packages:
#' @examplesIf rlang::is_installed("dplyr")
#' library(dplyr)
#' my_data %>% my_function()
For individual code blocks within examples:
#' @examples
#' if (rlang::is_installed("dplyr")) {
#' library(dplyr)
#' my_data %>% my_function()
#' }
CRAN enforces strict Title requirements:
Use Title Case
Capitalize all words except articles like 'a', 'the'. Use tools::toTitleCase() to help format.
Avoid Redundancy
Common phrases that get flagged:
Examples:
# BAD
Title: A Toolkit for the Construction of Modeling Packages for R
# GOOD
Title: Construct Modeling Packages
# BAD
Title: Command Argument Parsing for R
# GOOD
Title: Command Argument Parsing
Quote Software/Package Names
Put all software and R package names in single quotes:
# GOOD
Title: Interface to 'Tiingo' Stock Price API
Length Limit
Keep titles under 65 characters.
Never Start With Forbidden Phrases
CRAN will reject descriptions starting with:
"This package"
Package name
"Functions for"
Description: This package provides functions for rendering slides. Description: Functions for rendering slides to different formats.
Description: Render slides to different formats including HTML and PDF.
Expand to 3-4 Sentences
Single-sentence descriptions are insufficient. Provide a broader description of:
What the package does
Why it may be useful
Types of problems it helps solve
Description: Render slides to different formats.
Description: Render slides to different formats including HTML and PDF. Supports custom themes and progressive disclosure patterns. Integrates with 'reveal.js' for interactive presentations. Designed for technical presentations and teaching materials.
Quote Software Names, Not Functions
# BAD
Description: Uses 'case_when()' to process data.
# GOOD
Description: Uses case_when() to process data with 'dplyr'.
Software, package, and API names get single quotes (including 'R'). Function names do not.
Expand All Acronyms
All acronyms must be fully expanded on first mention:
# BAD
Description: Implements X-SAMPA processing.
# GOOD
Description: Implements Extended Speech Assessment Methods Phonetic
Alphabet (X-SAMPA) processing.
Publication Titles Only in Double Quotes
Only use double quotes for publication titles, not for phrases or emphasis:
# BAD
Description: Handles dates like "the first Monday of December".
# GOOD
Description: Handles dates like the first Monday of December.
All URLs Must Use HTTPS
CRAN requires https:// protocol for all URLs. HTTP links will be rejected.
# BAD
URL: http://paleobiodb.org/
# GOOD
URL: https://paleobiodb.org/
No Redirecting URLs
CRAN rejects URLs that redirect to other locations. Example rejection:
Found the following (possibly) invalid URLs:
URL: https://h3geo.org/docs/core-library/coordsystems#faceijk-coordinates
(moved to https://h3geo.org/docs/core-library/coordsystems/)
Use urlchecker Package
# Find redirecting URLs
urlchecker::url_check()
# Automatically update to final destinations
urlchecker::url_update()
Ignore URLs That Will Exist After Publication
Some URLs that don't currently resolve will exist once the package is published on CRAN. These should NOT be changed:
https://cran.r-project.org/package=pkgname)https://www.r-pkg.org/badges/version/pkgname)https://cranchecks.info/badges/pkgname)When urlchecker::url_check() flags these URLs, leave them as-is. They are aspirational URLs that will work once the package is on CRAN.
Check for Invalid File URIs
Relative links in README must exist after package build. Common issue:
Found the following (possibly) invalid file URI:
URI: CODE_OF_CONDUCT.md
From: README.md
This occurs when files are in .Rbuildignore. Solutions:
.Rbuildignoreusethis::use_code_of_conduct() which generates sections without relative linksCopyright Holder Role
Always add [cph] role to Authors field, even if you're the only author:
# Required
Authors@R: person("John", "Doe", role = c("aut", "cre", "cph"))
Posit-Supported Packages
For packages in Posit-related GitHub organizations (posit-dev, rstudio, r-lib, tidyverse, tidymodels) or maintained by someone with a @posit.co email address, include Posit Software, PBC as copyright holder and funder:
Authors@R: c(
person("Jane", "Doe", role = c("aut", "cre"),
email = "jane.doe@posit.co"),
person("Posit Software, PBC", role = c("cph", "fnd"),
comment = c(ROR = "03wc8by49"))
)
LICENSE Year
Update LICENSE year to current submission year:
# If LICENSE shows 2024 but submitting in 2026
# Update: 2024 → 2026
Method References
CRAN may ask:
If there are references describing the methods in your package, please add these in the description field...
If there are no references, reply to the email explaining this. Consider adding a preemptive note in cran-comments.md:
## Method References
There are no published references describing the methods in this package.
The package implements original functionality for [brief description].
Work through these files systematically:
@return, @examples, @examplesIf, @noRd)devtools::build_readme()DESCRIPTION Title:
# Before
Title: A Toolkit for the Construction of Modeling Packages for R
# After
Title: Construct Modeling Packages
DESCRIPTION Description:
# Before
Description: This package provides functions for rendering slides.
# After
Description: Render slides to different formats including HTML and PDF.
Supports custom themes and progressive disclosure. Integrates with
'reveal.js' for interactive presentations.
Function Documentation:
# Before - Missing @return
#' Calculate total
#' @param x Values
#' @export
calc_total <- function(x) sum(x)
# After - Complete documentation
#' Calculate total
#' @param x Numeric values to sum
#' @return A numeric value representing the sum
#' @examples
#' calc_total(1:10)
#' @export
calc_total <- function(x) sum(x)
tools::toTitleCase() - Format titles with proper capitalizationurlchecker::url_check() - Find problematic URLsurlchecker::url_update() - Fix redirecting URLsusethis::use_news_md() - Create NEWS.mdusethis::use_cran_comments() - Create cran-comments.mddevtools::build_readme() - Re-render README.md from README.Rmdusethis::use_code_of_conduct() - Add CoC without relative linksusethis::use_build_ignore() - Ignore files in R package buildusethis::use_package() - Add a package dependency to DESCRIPTIONUse this checklist to ensure nothing is missed before submission:
NEWS.md exists and documents changes for this versioncran-comments.md exists with submission notesdevtools::build_readme() was runinstall.packages("pkgname"))Title: uses title caseTitle: has no redundant phrases ("A Toolkit for", "Tools for", "for R")Title: quotes all software/package names in single quotesTitle: is under 65 charactersDescription: does NOT start with "This package", package name, or "Functions for"Description: is 3-4 sentences explaining purpose and utilityDescription: quotes software/package/API names (including 'R') but NOT function namesDescription: expands all acronyms on first mentionDescription: uses double quotes only for publication titles@return documentation@examples\dontrun{} unless truly necessary@examplesIf or if guards::: notation or @noRdurlchecker::url_check() was run.Rbuildignore filescran-comments.mdWeekly Installs
89
Repository
GitHub Stars
205
First Seen
Feb 10, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode82
github-copilot81
claude-code79
codex79
gemini-cli79
amp78
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
123,700 周安装
usethis::use_tidy_description() - Tidy up DESCRIPTION formattingAuthors@R: includes copyright holder with [cph] roleperson("Posit Software, PBC", role = c("cph", "fnd"), comment = c(ROR = "03wc8by49"))