R: Track the executed code lines of a function or method.
inspect
R Documentation
Track the executed code lines of a function or method.
Description
inspect examines and modifies the source code of a function or
method. After the modification of the source code, the modified function
will be executed and the result of the tracking process will be
stored. To store the information a tracker environment with the
name track must exist.
Note, that not all R code constructs can be handled at the current
state. In some cases it is not possible to track a specific code line.
Therefore, clearly structured code with consequent use of
opening and closing braces to indicate conditional expressions can
prevent these parser problems.
Usage
inspect(expr, track = track)
Arguments
expr
Any R function or method call.
track
list object, as returned by a call to tracker.
Details
The return value of inspect is the result returned by
the function executed. If the function has no return value nothing is
returned either.
Author(s)
Thomas König, Klaus Jünemann
& Matthias Burger
See Also
tracker for the call tracking object, and
printHTML.trackInfo for displaying results.
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), track = track)
## get the tracked function call info
resTrack <- track$getTrackInfo()
## create HTML sites
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/inspect.Rd_%03d_medium.png", width=480, height=480)
> ### 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), track = track)
>
> ## get the tracked function call info
> resTrack <- track$getTrackInfo()
>
> ## create HTML sites
> printHTML.trackInfo(resTrack)
>
>
>
>
>
> dev.off()
null device
1
>