协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
create-r-package【开发与工程】Scaffold a new R package with complete structure including DESCRIPTION, NAMESPACE, testthat, roxygen2, renv, Git, GitHub Actions CI, and development configuration files (.Rprofile, .Renviron.example, CLAUDE.md). Follows usethis conventions and tidyverse style. Use when starting a new R package from scratch, converting loose R scripts into a structure…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Scaffold full R pkg w/ modern tools + best practices.
.)usethis::create_package("packagename")
setwd("packagename")
Got: Dir w/ DESCRIPTION, NAMESPACE, R/, man/.
If err: Install usethis (install.packages("usethis")). Dir must not exist.
Edit w/ accurate metadata:
Package: packagename
Title: What the Package Does (Title Case)
Version: 0.1.0
Authors@R:
person("First", "Last", , "email@example.com", 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
Got: Valid DESCRIPTION, R CMD check no metadata warns.
If err: Warns → Title Case, Description >1 sentence, Authors@R valid 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")
Got: LICENSE, README.md, NEWS.md, tests/, .git/, .github/workflows/.
If err: use_*() fail → install missing dep + rerun. .git/ exists → use_git() skips.
.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$
Got: .Rprofile, .Renviron.example, .Rbuildignore created. Dev files excluded from build.
If err: .Rprofile startup err → check syntax. requireNamespace() guards → prevent fail on missing pkgs.
renv::init()
Got: renv/ + renv.lock. Local lib active.
If err: Install renv (install.packages("renv")). Hang → check network / options(timeout = 600).
R/packagename-package.R:
#' @keywords internal
"_PACKAGE"
## usethis namespace: start
## usethis namespace: end
NULL
Got: File w/ "_PACKAGE" sentinel. devtools::document() → pkg-level help.
If err: Filename = R/<packagename>-package.R. "_PACKAGE" standalone, not in fn.
Create CLAUDE.md in root w/ proj-specific instructions for AI.
Got: CLAUDE.md in root w/ conventions + build cmds + arch notes.
If err: Unsure → pkg name, 1-line desc, dev cmds (devtools::check(), devtools::test()), non-obvious conventions.
devtools::check() → 0 err, 0 warn.Rprofile loads no errrenv::status() OK.gitignoreavailable::available("packagename") pre-commit.Rprofile, .Renviron, renv/) must be excludedEncoding: UTF-8 in DESCRIPTION# 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 — doc fnswrite-testthat-tests — add testssetup-github-actions-ci — CI/CD configmanage-renv-dependencies — deps mgmtwrite-claude-md — AI instr