RUNIT testing of remote packaging

I follow the prompts of this question , but I'm impatient, and I would like to run my tests faster, without waiting for 30+ checks what R CMD check srccauses before checking tests.

what I thought I could do was add an option --standaloneto the doRUnit.Rone suggested in that R-wiki page , so that I can run unit tests regardless 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 files test.*\.R, regardless of the directory from which I call the script.

the remaining problem is that the doRUnit.Rscript loads the library installed , it is not the source()files that make up the library.

, R, ?

, ( "", "" ), ?

+3
2

, R source(), , - source(dir("/some/Path", pattern="*.R", full.names=TRUE).

, R CMD INSTALL . , . , , , , . . .

: , R 2.10.1 R CMD INSTALL:

2.10.1

R CMD INSTALL --no-R, --no-libs, -no-data, -no-help, -no-demo, -no-exec -no-inst . (, ).

.

+3

/ script.

doRUnit.R --standalone 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))
  }
0

Source: https://habr.com/ru/post/1725713/


All Articles