inspect: Track the executed code lines of a function or method.

View source: R/inspector.r

inspectR 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 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(resTrack, baseDir=tempdir())

RUnit documentation built on May 29, 2024, 12:30 p.m.