Niels Richard Hansen
2010-Dec-17 17:42 UTC
[Rd] How to use the RUnit tracker in unit tests?
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
Apparently Analagous Threads
- RUnit - need advice on a good directory structure or tips...
- what don't I get about numeric/double comparisons in R way?
- Error from sparse pattern matrix product
- The permutation of one vector into another
- 'identical' and the warning "ignoring non-pairlist attributes"