[Rd] Call function only when running via R CMD check?

Henrik Bengtsson hb at biostat.ucsf.edu
Fri Nov 4 02:36:50 CET 2011


On Wed, Nov 2, 2011 at 7:40 PM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
> I'd like to be able to change some default settings only in the case
> when checking a package with 'R CMD check'.  More precisely, I'd like
> to execute a piece of R code before the Rd examples and/or test
> scripts are evaluated by 'R CMD check'.  Is there a mechanism in 'R
> CMD check' that makes this possible?  If not, is there a way to detect
> that you are running via 'R CMD check', e.g. an R or an environment
> variable being set?
>
> The background for this is that some of my packages' examples are
> using memoization to cache computational expensive results (via the
> 'R.cache' package).  These are cached to files which are by default
> stored under ~/.Rcache/.   It turns out that these files live beyond
> the check cycle of the CRAN check servers, meaning that the next time
> the package is checked memoized results will be picked up.  If I could
> detect that we're running via 'R CMD check', then I could change the
> default cache directory to a temporary directory (e.g. tempdir()) that
> will be clean out automatically.
>
> This is not a critical problem, because for now I could explicitly
> turn off the memoization in the code of my examples/regression tests,
> but the above would be a more generic solution.

I've got a few off-line suggestions (thanks).  It seems that there is
no certain way of doing this, but one can look for various evidences
available in the current R session, such as looking at the content of
commandArgs(), search() and getwd().  Trying to infer whether 'R CMD
check' runs and if it checks examples or tests based on this won't be
100% safe, but probably good enough.  Best would be if 'R CMD check'
would pass a environment variable (or a command argument) to the R
session reporting on its state (that's a wish), e.g.

R R_CMD_CHECK_STATE="checkingExamples" LANGUAGE=en --vanilla -f MyPackage-Ex.R
R R_CMD_CHECK_STATE="checkingTest" -f myTest.R --restore --save --vanilla

/Henrik

>
> Thanks
>
> Henrik
>



More information about the R-devel mailing list