Skip to content

Commit 31033df

Browse files
author
smeyer
committed
add --run-demo option for R CMD check
git-svn-id: https://svn.r-project.org/R/trunk@87606 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 18683f9 commit 31033df

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

doc/NEWS.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@
365365
\command{bash} scripts and bashisms in components of
366366
\command{autoconf}-generated \command{configure} scripts.
367367
368+
\item \command{R CMD check} gains option \option{--run-demo} to
369+
check demo scripts like tests.
370+
368371
\item \code{R CMD build} now supports \option{--compression =
369372
zstd} on platforms with sufficient support for \command{zstd}.
370373
}

doc/manual/R-exts.texi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,11 @@ The @file{data} subdirectory is for data files: @xref{Data in packages}.
13971397

13981398
The @file{demo} subdirectory is for @R{} scripts (for running @emph{via}
13991399
@code{demo()}) that demonstrate some of the functionality of the
1400-
package. Demos may be interactive and are not checked automatically, so
1400+
package. Demos may be interactive and are not checked
1401+
automatically@footnote{As from @R{} 4.5.0, @code{R CMD check} can be
1402+
invoked with option @option{--run-demo} to check demos like @file{tests},
1403+
including comparisons with optional reference outputs in
1404+
@file{.Rout.save} files.}, so
14011405
if testing is desired use code in the @file{tests} directory to achieve
14021406
this. The script files must start with a (lower or upper case) letter
14031407
and have one of the extensions @file{.R} or @file{.r}. If present, the

doc/manual/R-ints.texi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,6 +4261,11 @@ If set to a true value, also check the R code in common unit test
42614261
subdirectories of @file{tests} for undeclared package dependencies.
42624262
Default: false (but true for CRAN submission checks).
42634263

4264+
@item _R_CHECK_PACKAGES_USED_IN_DEMO_
4265+
Control whether R scripts in the @file{demo} directory should be checked
4266+
for packages used but not declared in the @file{DESCRIPTION} file.
4267+
Default: false unless command-line option @option{--run-demo} is specified.
4268+
42644269
@item _R_CHECK_SHLIB_OPENMP_FLAGS_
42654270
Check correct and portable use of @code{SHLIB_OPENMP_*FLAGS} in
42664271
@file{src/Makevars} (and similar).

src/library/tools/R/check.R

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,10 @@ add_dummies <- function(dir, Log)
732732
resultLog(Log, "SKIPPED")
733733
}
734734

735+
## Run the demos if requested (traditionally part of tests, as in base)
736+
if (dir.exists(file.path(pkgdir, "demo")))
737+
run_tests("demo")
738+
735739
## Run the package-specific tests.
736740
tests_dir <- file.path(pkgdir, test_dir)
737741
if (test_dir != "tests" && !dir.exists(tests_dir)) {
@@ -740,7 +744,7 @@ add_dummies <- function(dir, Log)
740744
}
741745
if (dir.exists(tests_dir) && # trackObjs has only *.Rin
742746
length(dir(tests_dir, pattern = "\\.(R|r|Rin)$")))
743-
run_tests()
747+
run_tests(test_dir)
744748

745749
## Check package vignettes.
746750
setwd(pkgoutdir)
@@ -4637,30 +4641,41 @@ add_dummies <- function(dir, Log)
46374641
}
46384642
}
46394643

4640-
run_tests <- function()
4644+
## this is also used for --run-demo
4645+
run_tests <- function(test_dir = "tests")
46414646
{
4642-
if (!extra_arch && !is_base_pkg) {
4647+
is_demo <- test_dir == "demo"
4648+
check_packages_used <- !is_demo ||
4649+
config_val_to_logical(Sys.getenv("_R_CHECK_PACKAGES_USED_IN_DEMO_", do_demo))
4650+
if (check_packages_used && !extra_arch && !is_base_pkg) {
46434651
checkingLog(Log, "for unstated dependencies in ", sQuote(test_dir))
46444652
Rcmd <- paste(opW_shE_F_str,
46454653
sprintf("tools:::.check_packages_used_in_tests(\"%s\", \"%s\")\n", pkgdir, test_dir))
46464654

46474655
out <- R_runR2(Rcmd, "R_DEFAULT_PACKAGES=NULL")
46484656
if (length(out)) {
4649-
warningLog(Log)
4657+
if (is_demo) noteLog(Log) else warningLog(Log)
46504658
printLog0(Log, paste(c(out, ""), collapse = "\n"))
46514659
# wrapLog(msg_DESCRIPTION)
46524660
} else resultLog(Log, "OK")
46534661
}
46544662

4655-
if (test_dir == "tests")
4656-
checkingLog(Log, "tests")
4657-
else
4658-
checkingLog(Log, "tests in ", sQuote(test_dir))
4663+
if (is_demo) {
4664+
if (do_demo) {
4665+
checkingLog(Log, "demos")
4666+
do_tests <- TRUE
4667+
} else return()
4668+
} else {
4669+
if (test_dir == "tests")
4670+
checkingLog(Log, "tests")
4671+
else
4672+
checkingLog(Log, "tests in ", sQuote(test_dir))
4673+
}
46594674

46604675
run_one_arch <- function(arch = "")
46614676
{
46624677
testsrcdir <- file.path(pkgdir, test_dir)
4663-
testdir <- file.path(pkgoutdir, "tests")
4678+
testdir <- file.path(pkgoutdir, if (is_demo) "demo" else "tests")
46644679
if(nzchar(arch)) testdir <- paste(testdir, arch, sep = "_")
46654680
if(!dir.exists(testdir)) dir.create(testdir, mode = "0755")
46664681
if(!dir.exists(testdir)) {
@@ -6900,6 +6915,7 @@ add_dummies <- function(dir, Log)
69006915
" --no-vignettes do not run R code in vignettes nor build outputs",
69016916
" --no-build-vignettes do not build vignette outputs",
69026917
" --ignore-vignettes skip all tests on vignettes",
6918+
" --run-demo do run R scripts in 'demo' subdirectory",
69036919
" --run-dontrun do run \\dontrun sections in the Rd files",
69046920
" --run-donttest do run \\donttest sections in the Rd files",
69056921
" --use-gct use 'gctorture(TRUE)' when running examples/tests",
@@ -6992,6 +7008,7 @@ add_dummies <- function(dir, Log)
69927008
multiarch <- NA
69937009
force_multiarch <- FALSE
69947010
as_cran <- FALSE
7011+
do_demo <- FALSE
69957012
run_dontrun <- FALSE
69967013
run_donttest <- FALSE
69977014
stop_on_test_error <- TRUE
@@ -7053,6 +7070,8 @@ add_dummies <- function(dir, Log)
70537070
} else if (a == "--no-latex") {
70547071
stop("'--no-latex' is defunct: use '--no-manual' instead",
70557072
call. = FALSE, domain = NA)
7073+
} else if (a == "--run-demo") {
7074+
do_demo <- TRUE
70567075
} else if (a == "--run-dontrun") {
70577076
run_dontrun <- TRUE
70587077
} else if (a == "--run-donttest") {
@@ -7829,9 +7848,11 @@ add_dummies <- function(dir, Log)
78297848
"R_check_bin",
78307849
"build_vignettes.log",
78317850
"tests", "vign_test",
7851+
if (do_demo) "demo",
78327852
if(this_multiarch)
78337853
c(paste0("examples_", inst_archs),
78347854
paste0(pkgname, "-Ex_", inst_archs, ".Rout"),
7855+
if (do_demo) paste0("demo_", inst_archs),
78357856
paste0("tests_", inst_archs))
78367857
))
78377858
## Examples calling dev.new() give files Rplots*.pdf,

0 commit comments

Comments
 (0)