[R-pkg-devel] Installing Tests with R Build

Joshua Ulrich josh.m.ulrich at gmail.com
Sat Nov 25 15:20:23 CET 2017


On Thu, Nov 23, 2017 at 10:05 AM, Bill Denney <bill at denney.ws> wrote:
> Hi Joshua and Dirk,
>
>> On Nov 23, 2017, at 10:17, Dirk Eddelbuettel <edd at debian.org> wrote:
>>
>>
>> On 23 November 2017 at 08:07, Joshua Ulrich wrote:
>> | On Wed, Nov 22, 2017 at 4:21 PM, Bill Denney <bill at denney.ws> wrote:
>> | > When running R BUILD now (via Travis CI), I get an error that the build failed trying to build the vignettes.  For R CMD install, I can add --install-tests.  Is there a way to control R BUILD so that the installation includes test installation?
>> | >
>> | Put the tests you want to install into a directory inside the inst/
>> | directory (e.g. inst/tests/).
>>
>> Which happens to be the default mode of operations with RUnit.
>>
>> And it is a feature that I happen to _like_ a great deal because it permits
>> testing of the _installed_ package which is something you need in real life
>> when eg some of you system libraries may have change.
>
> Putting the tests there seems like a very reasonable solution to the immediate issue.  It contravenes the options to install (or not install) tests ("R CMD INSTALL --install-tests" loses meaning).  I'm going to update the structure of my vignette so that it detects if the tests are there and builds the vignette based on the existence of the tests (making it say "Please install the tests following these instructions...").
>
> I'm immediately ok with reworking the directory structure and tests, but I think it would be preferable long run to:
> Have R CMD BUILD gain an --install-args option so that installation arguments can be controlled (for situations like this and I'm sure others).
>
I just took a closer look at this, and I don't understand why any
change is necessary.  With a package created by package.skeleton():

josh at thinkpad: ~/git
> R CMD build anRpackage
* checking for file 'anRpackage/DESCRIPTION' ... OK
* preparing 'anRpackage':
* checking DESCRIPTION meta-information ... OK
* installing the package to process help pages
* saving partial Rd database
* creating vignettes ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building 'anRpackage_1.0.tar.gz'


josh at thinkpad: ~/git
> tar -ztf anRpackage_1.0.tar.gz
anRpackage/DESCRIPTION
anRpackage/NAMESPACE
anRpackage/R/
anRpackage/R/file.R
anRpackage/build/
anRpackage/build/partial.rdb
anRpackage/build/vignette.rds
anRpackage/inst/
anRpackage/inst/doc/
anRpackage/inst/doc/file.Rnw
anRpackage/inst/doc/file.pdf
anRpackage/man/
anRpackage/man/anRpackage-package.Rd
anRpackage/tests/
anRpackage/tests/unittests.R
anRpackage/vignettes/
anRpackage/vignettes/file.Rnw

The package builds successfully, and the tests are still in their
tests/ directory.  Now if I install without the --install-tests flag:

josh at thinkpad: ~/git
> R CMD INSTALL anRpackage_1.0.tar.gz 2>/dev/null

josh at thinkpad: ~/git
> ls -l ~/R/library/anRpackage/
total 32
-rw-r--r-- 1 josh josh  420 Nov 25 08:16 DESCRIPTION
drwxr-xr-x 2 josh josh 4096 Nov 25 08:16 doc
drwxr-xr-x 2 josh josh 4096 Nov 25 08:16 help
drwxr-xr-x 2 josh josh 4096 Nov 25 08:16 html
-rw-r--r-- 1 josh josh   59 Nov 25 08:16 INDEX
drwxr-xr-x 2 josh josh 4096 Nov 25 08:16 Meta
-rw-r--r-- 1 josh josh   72 Nov 25 08:16 NAMESPACE
drwxr-xr-x 2 josh josh 4096 Nov 25 08:16 R

You can see there's no tests/ directory.  Now with the --install-tests flag:

josh at thinkpad: ~/git
> R CMD INSTALL anRpackage_1.0.tar.gz --install-tests 2>/dev/null

josh at thinkpad: ~/git
> ls -l ~/R/library/anRpackage/
total 36
-rw-r--r-- 1 josh josh  420 Nov 25 08:17 DESCRIPTION
drwxr-xr-x 2 josh josh 4096 Nov 25 08:17 doc
drwxr-xr-x 2 josh josh 4096 Nov 25 08:17 help
drwxr-xr-x 2 josh josh 4096 Nov 25 08:17 html
-rw-r--r-- 1 josh josh   59 Nov 25 08:17 INDEX
drwxr-xr-x 2 josh josh 4096 Nov 25 08:17 Meta
-rw-r--r-- 1 josh josh   72 Nov 25 08:17 NAMESPACE
drwxr-xr-x 2 josh josh 4096 Nov 25 08:17 R
drwxr-xr-x 2 josh josh 4096 Nov 25 08:17 tests

The tests/ directory is present, and I can run the tests:

josh at thinkpad: ~/git
> Rscript -e 'tools::testInstalledPackage("anRpackage")'
Testing examples for package 'anRpackage'
Running specific tests for package 'anRpackage'
  Running 'unittests.R'
Running vignettes for package 'anRpackage'
  Running 'file.Rnw'

Someone could probably give you specific advice if you share a link to
the code and/or TravisCI log(s).

> Thank you (and Happy Thanksgiving to those celebrating it),
>
> Bill



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2017 | www.rinfinance.com



More information about the R-package-devel mailing list