Evaluate R expressions in an attached environment.
attach_eval(
unquoted_expr,
name = "local:utils",
pos = 2L,
warn.conflicts = TRUE,
...,
expr = substitute(unquoted_expr),
mask.ok = NULL
)The expression to be evaluated, This is automatically quoted.
The environment name. If an environment of that name already exists, it is reused, otherwise, a new environment is attached.
The position where to attach the environment, if creating a new
one. If an environment of name already exists, pos is ignored.
logical. If TRUE (the default), print warnings about objects in the attached environment that that are masking or masked by other objects of the same name.
Ignored.
An R language object. This is an escape hatch from the automatic
quoting of unquoted_expr.
character vector of names of objects that can mask objects on
the search path without signaling a warning if warn.conflicts is TRUE.
The result after evaluating expr, invisibly.
attach_eval({
my_helper_funct <- function(x, y) x + y
})
search() # environment "local:utils" is now attached
#> [1] ".GlobalEnv" "local:utils" "package:envir"
#> [4] "package:stats" "package:graphics" "package:grDevices"
#> [7] "package:utils" "package:datasets" "package:methods"
#> [10] "Autoloads" "tools:callr" "package:base"
my_helper_funct(1, 1) # the local utility is now available
#> [1] 2
detach(local:utils) # cleanup