Henrik Bengtsson
2011-Nov-03 02:40 UTC
[Rd] Call function only when running via R CMD check?
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
Henrik Bengtsson
2011-Nov-04 01:36 UTC
[Rd] Call function only when running via R CMD check?
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 >
Possibly Parallel Threads
- Memoize and vectorize a custom function
- ad4: WARNING - SETFEATURES SET TRANSFER MODE taskqueue timeout - on FreeBSD 6-STABLE
- Risk of readRDS() not detecting race conditions with parallel saveRDS()?
- Re: [PATCH v2] lib: Use qemu-img info -U option to avoid locking error.
- IVUsers pass is fragile. Is this okay? How can it be resolved?