The current implementation uses the 'closure trick' to hide all details from
the user and only allows to retrieve the results of the code inspection.
tracker is used to create a new environment to manage and store the results
of the tracking process. The inspect function requires such an
environment with the name "track" (currently mandatory). The tracker records how often each
and every function was called by inspect and summarizes the results of
all calls.
tracker$init initializes the tracker environment.
tracker$getTrackInfo returns a list with the tracked results of the
inspection process.
Usage
tracker()
Details
The 'trackInfo' S3 class object (list) has one entry for each
function on the inspect list with the following elements:
src
The source code of the function.
run
The number of executions for each line of code.
graph
A matrix. Each element in the matrix counts how often a
code line was called from the previous code line in the execution flow.
nrRuns
Counts how often the function was called.
funcCall
The declaration of the function.
Methods
init
initializes the tracker environment
addFunc
add function to the inspect tracking list
(internal use)
getSource
return the modified source code used for during inspection
the specified index (internal use)
bp
update tracking info for specified function
index (internal use)
getTrackInfo
return 'trackInfo' object
isValid
check 'trackInfo' object for conformance to
class contract
Author(s)
Thomas König, Klaus Jünemann
& Matthias Burger
See Also
inspect for the registration of functions & methods to
be on the tracking list, and
printHTML.trackInfo for displaying results
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), track = track)
resFoo2 <- inspect(foo(20), track = track)
resBar1 <- inspect(bar(30), track = track)
## 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)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
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 an HTML browser interface to help.
Type 'q()' to quit R.
> library(RUnit)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/RUnit/tracker.Rd_%03d_medium.png", width=480, height=480)
> ### 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), track = track)
>
> resFoo2 <- inspect(foo(20), track = track)
>
> resBar1 <- inspect(bar(30), track = track)
>
> ## 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)
>
>
>
>
>
> dev.off()
null device
1
>