如何在devtools::check()与devtools::build_vignettes()时排除耗时vignette?
Absolutely! There are straightforward ways to exclude time-consuming vignettes when running devtools::check() and devtools::build_vignettes()—here's how you can set this up:
devtools::check() You’ve got two reliable options here, depending on whether you want to skip specific vignettes or all of them temporarily:
Mark individual vignettes as skip-worthy in their YAML frontmatter
Open the slow vignette’s.Rmdfile, and addbuild: falseto the top YAML block. This tellsdevtools::check()to skip building and checking that particular vignette entirely:--- title: "My Super Slow Vignette" output: rmarkdown::html_vignette build: false ---This is the most maintainable approach because it’s tied directly to the vignette itself—anyone working on your package will see which ones are excluded by default.
Temporarily skip specific vignettes via environment variables
If you don’t want to modify the vignette files, you can set an environment variable to exclude specific paths before runningcheck():# Exclude one or more vignettes (separate with commas if multiple) Sys.setenv("_R_CHECK_BUILD_VIGNETTES_EXCLUDE_" = "vignettes/my-slow-vignette.Rmd") devtools::check()To skip all vignettes temporarily, you can pass a build argument instead:
devtools::check(build_args = "--no-build-vignettes")
devtools::build_vignettes() By default, this function builds all vignettes in your vignettes/ folder. To exclude slow ones, you have two simple strategies:
Explicitly list only the vignettes you want to build
Use thevignettesparameter to specify the paths of the fast vignettes you want to process:devtools::build_vignettes(vignettes = c("vignettes/fast-vignette-1.Rmd", "vignettes/fast-vignette-2.Rmd"))Dynamically exclude slow vignettes from the full list
If you have many vignettes, you can programmatically filter out the slow ones instead of listing every fast one:# Get all vignette paths all_vignettes <- list.files("vignettes", pattern = "\\.Rmd$", full.names = TRUE) # Define the slow ones to exclude slow_vignettes <- c("vignettes/my-slow-vignette.Rmd", "vignettes/another-slow-one.Rmd") # Build only the fast ones devtools::build_vignettes(vignettes = setdiff(all_vignettes, slow_vignettes))
For most workflows, marking vignettes with build: false in their YAML is the cleanest long-term solution for check(), while explicitly targeting fast vignettes works best for build_vignettes() when you still want to generate some documentation quickly.
内容的提问来源于stack exchange,提问作者user2978524

