[R-pkg-devel] Skipping tests on CRAN

Sebastian Meyer @eb@meyer @end|ng |rom |@u@de
Wed Apr 21 12:03:02 CEST 2021


Am 21.04.21 um 08:35 schrieb Mark van der Loo:
> Hi Ott,
> 
> There is no documented way to detect whether you are running on CRAN. So
> there is nothing to rely on, on that side.
> 
> You can only make your own machine detectable by the test code. For example
> by setting an environment variable that identifies your machine and make
> test execution depend on the value of that environment variable. This is
> what tinytest does under the hood.

You could add the following at the start of a script containing slow tests:

if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
    message("skipping slow tests")
    q("no")
}
## slow tests follow here ...

Of course, you could use a different name for the environment variable,
e.g., "R_PKGNAME_ALL_TESTS", or test with as.logical() to allow both
"TRUE" and "true" values:

if (!isTRUE(as.logical(Sys.getenv("R_PKGNAME_ALL_TESTS")))) q("no")

Quitting from test scripts as above is frequently used in R's own test
suite, for example in the regression tests for message translations:

if (!capabilities("NLS")) {
    message("no natural language support")
    q("no")
}

Don't run such code in an interactive session if you don't want to quit
R. ;)

An alternative is the R CMD check --test-dir=inst/slowTests approach
mentioned in the WRE manual at
https://CRAN.R-project.org/doc/manuals/r-devel/R-exts.html#Checking-packages
.

Best regards,

	Sebastian

> 
> Best,
> Mark
> 
> 
> 
> 
> 
> On Wed, Apr 21, 2021 at 7:17 AM Ott Toomet <otoomet using gmail.com> wrote:
> 
>> Hi packagers,
>>
>> what is the best way to skip certain tests on CRAN?  So far I have included
>> certain test files in .Rbuildignore and run the tests on the package
>> directory.  But now when moving to Authors using R format, I get errors about
>> missing maintainer etc.
>>
>> I know there are options in testthat, tinytest and such, are these the best
>> options with least dependencies and assumptions built in?
>>
>> I sort of remember something in base R but cannot find anything when
>> looking for it now.
>>
>> Cheers,
>> Ott
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-package-devel using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list