tron.function: tron - Wrap a function in logging code

Description Usage Arguments Details See Also Examples

Description

Create a logged copy of a function. Every time the new function is called, all three functions are called in order:

  1. pre

  2. f

  3. post

Usage

1
2
3
4
5
## S3 method for class 'function'
.tron(x, pre, post = pre)

## S3 method for class 'function'
.troff(x)

Arguments

x

a function to decorate

pre

a function, to be called before f

post

a function, to be called after f

Details

Wrapped functions carry a “tron” attribute, which can be tested for using is.tron. The original function f can be extracted using troff.

See Also

http://en.wikipedia.org/wiki/Decorator_pattern and memoise for another example of “decorator” functions.

Examples

1
2
3
4
5
f <- tron(sum, message)
f(1:10)
is.tron(f)
f <- troff(f)
f(1:10)

nfultz/tron documentation built on May 23, 2019, 4:41 p.m.