본문으로 건너뛰기
cccskills
무료GitHub에 공개

r-package-testing-workflow

Test and check R packages with devtools, testthat, CRAN-style checks, and built source tarballs. Use when running package tests, release checks, coverage, or focused R tests.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

실행 점수 미검증

설치 방법 보기

포함된 파일(1)

  • SKILL.md6.0 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

R Package Testing Workflow

Run commands from the package root. Check that DESCRIPTION, NAMESPACE, and required package metadata are valid before running tests.

Use this skill for package test and check decisions. Use github-actions-ci for GitHub Actions matrices, dependency setup, coverage jobs, and CI artifacts.

Decision flow

  1. If devtools is installed:
    • Full test suite: devtools::test()
    • Full CRAN-style check: devtools::check(args = c("--as-cran"))
  2. Without devtools:
    • Build a source tarball: R CMD build .
    • Check that tarball: R CMD check --as-cran <built-tarball>
  3. For focused work, use devtools::test(filter = "...") or testthat::test_file() only when a specific test was requested.

Do not use R CMD check --as-cran . as the preferred full workflow. Check the built source tarball.

Prerequisites

For testthat 3rd edition, confirm:

Suggests: testthat (>= 3.0.0)
Config/testthat/edition: 3

The standard tests/testthat.R file should run the installed-package check:

library(testthat)
library(mypackage)

test_check("mypackage")

Commands

# Complete package test suite
devtools::test()

# Focused tests, only when requested
devtools::test(filter = "addition")

# One test file, only when requested
testthat::test_file("tests/testthat/test_main.R")

# Full CRAN-style check
devtools::check(args = c("--as-cran"))

The lower-level tarball workflow from R is:

R CMD build .
R CMD check --as-cran <built-tarball>

On Windows, use PowerShell to select the newest tarball created by the build:

R CMD build .
$tarball = Get-ChildItem -File -Filter "*.tar.gz" |
  Sort-Object LastWriteTime -Descending |
  Select-Object -First 1 -ExpandProperty FullName
R CMD check --as-cran "$tarball"

If devtools is installed but you need to check the exact artifact:

tarball <- devtools::build()
system2("R", c("CMD", "check", "--as-cran", shQuote(tarball)))

Source and installed packages

devtools::test() is for fast source-package feedback. It does not prove that the built package installs or that all files made it into the tarball.

Use pkgload::load_all() with testthat::test_dir() only to diagnose unusual source-loading problems. It is not the preferred package test workflow.

The tarball check runs the installed-package path through test_check(). Use that path for release evidence, especially when the package has native code, compiled libraries, installation hooks, or package data.

Focused tests, reporters, and skips

Use focused tests for debugging, not as evidence that the full suite passes:

devtools::test(filter = "addition")
testthat::test_file("tests/testthat/test_main.R", reporter = "progress")

Useful reporters include progress, summary, tap, junit, and list.

Skip only for a stated condition:

test_that("optional feature", {
  skip_if_not_installed("pkgname")
  skip_on_os("windows")
  expect_true(feature_works())
})

Avoid broad skip_on_ci() use. Review skipped tests in CI so skips do not hide core failures.

Fixtures and isolation

For files under tests/testthat/fixtures, use testthat::test_path():

data_file <- testthat::test_path("fixtures", "sample.csv")
data <- read.csv(data_file)

Use system.file() for resources installed under inst/. Use tempdir() for temporary files. Restore options and global state with on.exit().

Make random tests repeatable:

set.seed(123)

Also control time zones, locales, encodings, temporary paths, and network use when those affect results.

Parallel tests

Parallel tests are opt-in and need testthat 3rd edition:

Config/testthat/parallel: true
TESTTHAT_PARALLEL=false
TESTTHAT_CPUS=4

Run the full suite serially at least once. Run a separate parallel job when the package enables parallel tests. Do not share mutable fixture paths or depend on test-file order. Use TESTTHAT_PARALLEL=false to debug failures.

Checks and diagnostics

Treat errors as failures. Investigate warnings. Classify every note as accepted or unresolved. Preserve the tarball, check output, .Rcheck directory, and session information when a CI check fails.

For structured results, use rcmdcheck:

result <- rcmdcheck::rcmdcheck(
  path = tarball,
  args = "--as-cran",
  check_dir = "check-output",
  error_on = "warning",
  timeout = 20 * 60
)
print(result)

Coverage and snapshots

Run coverage separately from the main OS/R matrix:

coverage <- covr::package_coverage(type = "tests", clean = TRUE)
print(covr::percent_coverage(coverage))

Coverage does not replace tests. Justify exclusions.

Commit testthat snapshots under tests/testthat/_snaps/. Review snapshot changes. Normalize timestamps, paths, random IDs, locale output, and other unstable values before snapshotting. Use snapshot_accept() only after understanding the change.

Release checks

Before release:

  • Run the complete suite and a fresh tarball check.
  • Run devtools::document() if documentation is generated.
  • Check examples, vignettes, URLs, DOI links, spelling, and cran-comments.md.
  • Run pkgdown::build_articles(new_process = TRUE) when the package uses pkgdown.
  • Run revdepcheck::revdep_check() when reverse dependencies exist.
  • For native code, add ASAN or UBSAN checks where practical. These supplement normal tests and checks.

Minimal checklist

  • Package root and metadata are valid.
  • testthat 3rd edition is configured when used.
  • Full suite passes with no unexplained skips.
  • Built tarball passes R CMD check --as-cran.
  • Errors, warnings, and notes are reviewed.
  • Release-only checks are complete when applicable.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Distills enduring architectural decisions and design rationale from wave orchestration plans or historical git changes into structured, tracked Architecture Decision Records (ADRs). Use pre-wave to resolve active architectural constraints or post-wave to record enduring decisions in docs/decisions/.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

AndrewBrown-USDA/aigb-skills-usda72026년 10월 24일 업데이트

Create and maintain AGENTS.md files for project onboarding and grounding. Use when initialized in a new project, when project structure changes significantly, or when creating subfolder-level AGENTS.md files for complex monorepos.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

AndrewBrown-USDA/aigb-skills-usda72026년 10월 24일 업데이트

Audit and update an arbitrary codebase to follow the Code.mil federal open-source licensing model (MIT with 17 U.S.C. Section 105 disclaimers and INTENT.md), including CRAN/R package DESCRIPTION setup.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

AndrewBrown-USDA/aigb-skills-usda72026년 10월 24일 업데이트

Migrates ArcPy and ArcGIS Pro workflows to explicit, testable open-source Python geospatial workflows. Use when removing ArcPy dependencies, porting geoprocessing scripts, or documenting ArcGIS behavior that will not be migrated.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

AndrewBrown-USDA/aigb-skills-usda72026년 10월 24일 업데이트

Adversarial tester and UX/documentation stress-tester that acts like a clumsy, literal-minded, or overwhelmed user to break systems, expose design flaws, and highlight confusing documentation. Use when the user asks to run "bull in a china shop" testing, stress-test an API/CLI/library/doc/workflow, find traps, test how a user might misuse a feature, or evaluate how documentation is interpreted.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

AndrewBrown-USDA/aigb-skills-usda72026년 10월 24일 업데이트

caveman

무료

Ultra-compressed communication mode that cuts output tokens while keeping technical accuracy. Levels: lite, full, ultra and the wenyan variants. Use for /caveman, "caveman mode", "talk like caveman", "be brief" or "less tokens".

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

AndrewBrown-USDA/aigb-skills-usda72026년 10월 24일 업데이트

AndrewBrown-USDA의 스킬 모두 보기

이 스킬의 문제 신고