[R-pkg-devel] How to run R CMD CHECK with the installation directory set to read-only ?

Uwe Ligges ||gge@ @end|ng |rom @t@t|@t|k@tu-dortmund@de
Thu Jan 30 10:18:24 CET 2025



On 29.01.2025 18:13, Craig Gower-Page wrote:
> Hi,
> 
> A package of ours had its test code throw an error during its R CMD
> CHECK on CRAN due to it attempting to write files to the installation
> directory. We were wondering how best to replicate this test on our
> local machines as we are unable to see any direct options / flags /
> hooks within R CMD CHECK that allows you to specify that the
> installation directory should be set to read-only ?
> 
>  From the "Writing R extensions" manual there appears to be an option
> that allows you to run R CMD CHECK on an installed package (I think
> technically it is running on the source package but it suppresses the
> installation step and uses the pre-installed version for running the
> tests). Quoting the manual below:
> 
>> It is possible to install a package and then check the installed package. To do so first install the package and keep a log of the installation:
>> R CMD INSTALL -l libdir pkg > pkg.log 2>&1
>> and then use
>> Rdev CMD check -l libdir --install=check:pkg.log pkg
> 
> This appears to do what we need in that we can first install the
> package locally, set the directory to read-only with `chmod 500` and
> then run R CMD CHECK using the arguments as specified above from the
> manual.

Yes, or mount it read-only


> HOWEVER - this approach appears to have a bug in that if the source
> code doesn't have an explicit `Author` and `Maintainer` field then the
> check will fail; that is to say it doesn't appear to be able to expand
> the `Author using R` field when running in this mode.

First you build the package via R CMD build and then you can unpack it, 
voila.


> 
> So to summarise my questions are:
> 
> * Is my described use of Rdev CMD check -l libdir
> --install=check:pkg.log pkg the correct way of using R CMD CHECK to
> test if the installed package is writing to the installation directory
> ?

At least that is what CRAN does during its regular checks anyway.

> * If not, what is the recommended way of using R CMD CHECK to catch
> this (e.g. how to replicate how CRAN runs R CMD CHECK to catch this) ?
> * If yes, is it regarded as a bug or not that R CMD CHECK on installed
> packages only works for packages that have an explicit Author /
> Maintainer field and not just a Author using R field?

It is fine, as described above. YOu always have to run R CMD build 
before checking as a package may also have build time actions (e.g. for 
the manuals) that oetherwise would not be executed.

Best,
Uwe Ligges



> With regards to the potential bug with R CMD CHECK; I tested this on R
> 4.4.2 on Mac OS Sonoma and have uploaded a small test script to GitHub
> that demonstrates it:
> https://gist.github.com/gowerc/248f398f421750f7673019d1989cbe6f#file-simple_script-sh
> 
> 
> Kind Regards
> 
> Craig Gower-Page
> 
> ______________________________________________
> 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