From hb at biostat.ucsf.edu  Thu Nov  3 03:40:26 2011
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Wed, 2 Nov 2011 19:40:26 -0700
Subject: [Rd] Call function only when running via R CMD check?
Message-ID: <CAFDcVCR+KazDBc-b0jhn8HkXSC6kPZrVg++0uw_tMtH-V5FB5Q@mail.gmail.com>

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.

Thanks

Henrik



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