[Rd] How to use the RUnit tracker in unit tests?

Niels Richard Hansen Niels.R.Hansen at math.ku.dk
Fri Dec 17 18:42:53 CET 2010


R-developers

Does anybody know how I incorporate the use of the tracker in RUnit
in the unit tests?

I have read the RUnit Vignette, help pages and searched around,
but I could find no examples of using 'inspect' in the unit
test functions. Moreover, doing so, I tried something like

library(RUnit)
myFunction <- function(x) {
	return(x)
}
track <- tracker()
track$init()

test.someTestFunction <- function() {
   y <- 10
   res <- inspect(myFunction(y), track = track)
   checkEquals(res, 10)
}

which works fine, when calling test.someTestFunction() from
the command line, but embedded in a test suite, I get
Error in eval(expr, envir, enclos) : object 'y' not found

Another question/suggestion: The 'inspect' function inserts
track points in the code, and this could perhaps be used
differently. Instead of doing it in a local copy of the code
(as I understand it is done), it could be done in the original
function, like 'trace' can replace the original code, I believe.
Then every subsequent call will be tracked, until inspection is
stopped. I imagine something like

startInspection(myFunction, track = track)
[ or startInspection(myFunction, signature = "numeric", track = track)]
myFunction(10)
stopInspection(myFunction)

Is this already around?

Best, Niels

-- 
Niels Richard Hansen                     Web:   www.math.ku.dk/~richard	
Associate Professor                      Email: Niels.R.Hansen at math.ku.dk
Department of Mathematical Sciences             nielsrichardhansen at gmail.com
University of Copenhagen                 Skype: nielsrichardhansen.dk	
Universitetsparken 5                     Phone: +1 510 502 8161	
2100 Copenhagen Ø
Denmark



More information about the R-devel mailing list