tags:

views:

102

answers:

2

I am following the hints to this question, but I'm impatient and I would like to run my tests more quickly, without having to wait for the 30+ checks that R CMD check src invokes before checking tests.

what I thought I could do was to add a --standalone option to the doRUnit.R suggested in that R-wiki page so that I could run the unit tests independently of R CMD.

I added these lines to the script:

  opt <- list(standalone=NULL)
  if(require("getopt", quietly=TRUE)) {
    ## path to unit tests may be given on command line, in which case
    ## we also want to move the cwd to this script
    opt <- getopt(matrix(c('standalone', 's', 0, "logical"),
                         ncol=4, byrow=TRUE))
    if(!is.null(opt$standalone)) {
      ## switch the cwd to the dir of this script
      args <- commandArgs()
      script.name <- substring(args[substring(args, 1, 7)=="--file="], 8, 1000)
      if(!is.null(script.name))
        setwd(dirname(script.name))
    }
  }

with this change, the script finds the test.*\.R files, independently from the directory from which I invoke the script.

the remaining problem now is that the doRUnit.R script loads the installed library, it does not source() the files that compose the library.

assuming that I want to load each and every file in the R directory, how would I do that?

assuming you have a better testing schema (satisfying the requirements "quick", "uninstalled"), what is it?

+2  A: 

You may have to manually loop over the files in the R directory and source() them, maybe with something like source(dir("/some/Path", pattern="*.R", full.names=TRUE).

But I have the feeling that R CMD INSTALL does a little more. You may be better off working from the installed code. And just running your unit tests directly, as you do and as the wiki page suggests, is already pretty good. So no better scheme from me. But keep us posted.

Edit: Also note that R 2.10.1 gives us new options to accelerate R CMD INSTALL:

2.10.1 NEW FEATURES

R CMD INSTALL has new options --no-R, --no-libs, --no-data, --no-help, --no-demo, --no-exec, and --no-inst to suppress installation of the specified part of the package. These are intended for special purposes (e.g. building a database of help pages without fully installing all packages).

That should help too.

Dirk Eddelbuettel
in the end, I'm mixing my own answer with yours: I first install the package and then I run the doRUnit --standalone. it's quicker and I see the output on the console.
mariotomo
later update: I've got a [Makefile](https://r-forge.r-project.org/scm/viewvc.php/\*checkout\*/pkg/inst/RUnit/Makefile?root=delftfews) in the unittests directory that defines a target (xtest) which produces output useful in a `*compilation*` buffer in emacs.
mariotomo
A: 

further additions/corrections to the script.

I can now invoke it as doRUnit.R --standalone or have it invoked by R CMD check

      if(!is.null(script.name)) {
        setwd(dirname(script.name))
        path <- '../inst/RUnit/'
      }
.
.
.

  if (is.null(opt$standalone)) {
    cat("\nRunning unit tests of installed library\n")
    library(package=pkg, character.only=TRUE)
  } else {
    cat("\nRunning unit tests of uninstalled library\n")
    source(dir("../R/", pattern=".*\\.R", full.names=TRUE))
  }
mariotomo