Macro-like functions
local.on.exit
is the analogue of on.exit
for "nested" or "macro" functions written with mlocal
.
# Inside an 'mlocal' function of the form # function( <<args>>, nlocal=sys.parent(), <<temp.params>>) mlocal({ <<code>> }) local.on.exit( expr, add=FALSE)
expr |
the expression to evaluate when the function ends |
add |
if TRUE, the expression will be appended to the existing |
Exit code will be executed before any temporary variables are removed (see mlocal
).
Mark Bravington
mlocal
, local.return
, local.on.exit
, do.in.envir
, and R-news 1/3
ffin <- function( nlocal=sys.parent(), x1234, yyy) mlocal({ x1234 <- yyy <- 1 # x1234 & yyy are temporary variables # on.exit( cat( yyy)) # would crash after not finding yyy local.on.exit( cat( yyy)) }) ffout <- function() { x1234 <- 99 ffin() x1234 # still 99 because x1234 was temporary } ffout()
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.