1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#' Use a specific plan for a future assignment
#'
#' @usage fassignment \%plan\% strategy
#'
#' @param fassignment The future assignment, e.g.
#' \code{x \%<-\% \{ expr \}}.
#' @param strategy The mechanism for how the future should be
#' resolved. See \code{\link{plan}()} for further details.
#'
#' @seealso
#' The \code{\link{plan}()} function sets the default plan for all futures.
#'
#' @export
`%plan%` <- function(fassignment, strategy) {
fassignment <- substitute(fassignment)
strategy <- substitute(strategy)
envir <- parent.frame(1)
## Temporarily use a different plan
oplan <- plan("list")
on.exit(plan(oplan, substitute = FALSE, .call = NULL, .cleanup = FALSE, .init = FALSE))
plan(strategy, substitute = FALSE, .call = NULL, .cleanup = FALSE, .init = FALSE)
eval(fassignment, envir = envir, enclos = baseenv())
}
|