Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Neal Fultz
committed
Feb 25, 2015
1 parent
80c954e
commit 3a1977b
Showing
6 changed files
with
174 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Generated by roxygen2 (4.1.0): do not edit by hand | ||
|
||
export(autolog) | ||
export(is.autologged) | ||
export(unwrap) | ||
export(wrap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
% Generated by roxygen2 (4.1.0): do not edit by hand | ||
% Please edit documentation in R/autolog.R | ||
\name{wrap} | ||
\alias{is.autologged} | ||
\alias{unwrap} | ||
\alias{wrap} | ||
\title{Wrap a function in logging code} | ||
\usage{ | ||
wrap(f, pre, post = pre) | ||
|
||
is.autologged(f) | ||
|
||
unwrap(f) | ||
} | ||
\arguments{ | ||
\item{f}{a function to decorate} | ||
|
||
\item{pre}{a function, to be called before \code{f}} | ||
|
||
\item{post}{a function, to be called after \code{f}} | ||
} | ||
\description{ | ||
Create a logged copy of a function. Every time the new function is called, all three functions are called in order: | ||
\enumerate{ | ||
\item \code{pre} | ||
\item \code{f} | ||
\item \code{post} | ||
} | ||
} | ||
\details{ | ||
Wrapped functions carry an \dQuote{autologged} attribute, which can be tested for using \code{is.autologged}. The original function \code{f} can be extracted | ||
using \code{unwrap}. | ||
} | ||
\examples{ | ||
f <- wrap(sum, message) | ||
f(1:10) | ||
is.autologged(f) | ||
f <- unwrap(f) | ||
f(1:10) | ||
} | ||
\seealso{ | ||
\url{http://en.wikipedia.org/wiki/Decorator_pattern} and \code{\link[memoise]{memoise}} for another example of \dQuote{decorator} functions. | ||
} | ||
|