R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("RUnit-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('RUnit') RUnit loaded. > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "checkFuncs" > > ### * checkFuncs > > flush(stderr()); flush(stdout()) > > ### Name: checkFuncs > ### Title: RUnit check functions > ### Aliases: checkEquals checkEqualsNumeric checkTrue checkException > ### DEACTIVATED > ### Keywords: programming > > ### ** Examples > > > checkTrue(1 < 2, "check1") ## passes fine [1] TRUE > ## checkTrue(1 > 2, "check2") ## appears as failure in the test protocol > > v <- 1:3 > w <- 1:3 > checkEquals(v,w) ## pasess fine [1] TRUE > names(v) <- c("A", "B", "C") > ## checkEquals(v,w) ## fails because v and w have different names > checkEqualsNumeric(v,w) ## passes fine because names are ignored [1] TRUE > > fun <- function(x) { + if(x) + { + stop("stop conditions signaled") + } + return() + } > > checkException(fun(TRUE)) ## passes fine Error in fun(TRUE) : stop conditions signaled [1] TRUE > ## checkException(fun(FALSE)) ## failure, because f raises no error > > ## DEACTIVATED("here one can document on the reason for deactivation") > > > > cleanEx(); ..nameEx <- "inspect" > > ### * inspect > > flush(stderr()); flush(stdout()) > > ### Name: inspect > ### Title: Track the executed code lines of a function or method. > ### Aliases: inspect > ### Keywords: programming > > ### ** Examples > > > ## example function > foo <- function(x){ + y <- 0 + for(i in 1:100) + { + y <- y + i + } + return(y) + } > > ## the name track is necessary > track <- tracker() > > ## initialize the tracker > track$init() > > ## inspect the function > ## res will collect the result of calling foo > res <- inspect(foo(10)) > > ## get the tracked function call info > resTrack <- track$getTrackInfo() > > ## create HTML sites > printHTML.trackInfo(resTrack) > > > > cleanEx(); ..nameEx <- "printHTML.trackinfo" > > ### * printHTML.trackinfo > > flush(stderr()); flush(stdout()) > > ### Name: printHTML.trackInfo > ### Title: Write HTML pages of the tracking result. > ### Aliases: printHTML.trackInfo > ### Keywords: programming > > ### ** Examples > > > ## example function > foo <- function(x){ + y <- 0 + for(i in 1:100) + { + y <- y + i + } + return(y) + } > > ## the name track is necessary > track <- tracker() > > ## initialize the tracker > track$init() > > ## inspect the function > ## res is the result of foo > res <- inspect(foo(10)) > > ## get the tracking info > resTrack <- track$getTrackInfo() > > ## create HTML pages > printHTML.trackInfo(resTrack) > > > > cleanEx(); ..nameEx <- "runit" > > ### * runit > > flush(stderr()); flush(stdout()) > > ### Name: runTestSuite > ### Title: Definition and execution of RUnit test suites. > ### Aliases: runTestSuite runTestFile defineTestSuite isValidTestSuite > ### Keywords: programming > > ### ** Examples > > > ## run some test suite > myTestSuite <- defineTestSuite("my test suite", "tests") > testData <- runTestSuite(myTestSuite) Error in runTestSuite(myTestSuite) : Invalid test suite. Test run aborted. > > ## prints detailed text protocol > ## to standard out: > printTextProtocol(testData, showDetails=TRUE) Error in .class1(object) : Object "testData" not found > > > > cleanEx(); ..nameEx <- "textProtocol" > > ### * textProtocol > > flush(stderr()); flush(stdout()) > > ### Name: textProtocol > ### Title: Printing a plain text or HTML version of an RUnit test run. > ### Aliases: printTextProtocol printHTMLProtocol print.RUnitTestData > ### summary.RUnitTestData getErrors > ### Keywords: programming > > ### ** Examples > > > ## run some test suite > myTestSuite <- defineTestSuite("my test suite", "tests") > testData <- runTestSuite(myTestSuite) Error in runTestSuite(myTestSuite) : Invalid test suite. Test run aborted. > > ## prints detailed text protocol > ## to standard out: > printTextProtocol(testData, showDetails=TRUE) Error in .class1(object) : Object "testData" not found > ## prints detailed html protocol > ## to standard out > printHTMLProtocol(testData) Error in .class1(object) : Object "testData" not found > > > > > cleanEx(); ..nameEx <- "tracker" > > ### * tracker > > flush(stderr()); flush(stdout()) > > ### Name: tracker > ### Title: Tracking the results of the inspect process. > ### Aliases: tracker > ### Keywords: programming > > ### ** Examples > > > ## example functions > foo <- function(x){ + y <- 0 + for(i in 1:100) + { + y <- y + i + } + return(y) + } > > bar <- function(x){ + y <- 0 + for(i in 1:100) + { + y <- y - i + } + return(y) + } > > > ## the object name track is 'fixed' (current implementation) > track <- tracker() > > ## initialize the tracker > track$init() > > ## inspect the function > ## resFoo1 will contain the result of calling foo(50) > resFoo1 <- inspect(foo(50)) > > resFoo2 <- inspect(foo(20)) > > resBar1 <- inspect(bar(30)) > > ## get the tracked function call info for all inspect calls > resTrack <- track$getTrackInfo() > > ## create HTML sites in folder ./results for all inspect calls > printHTML.trackInfo(resTrack) > > > > ### *