Starts a SecureSession, passes it to fn, and closes it when fn
returns or fails. Use it when you want several calls to share one session,
for example to build up variables across calls, without having to
remember to close it.
Usage
with_secure_session(fn, tools = list(), sandbox = TRUE, ...)Arguments
- fn
A function that receives a SecureSession as its first argument.
- tools
List of
securer_tool()objects to register in the session.- sandbox
Logical, whether to enable OS-level sandboxing (default
TRUE).- ...
Additional arguments passed to SecureSession
$new().
Examples
# \donttest{
# Run multiple commands on the same session
result <- with_secure_session(function(session) {
session$execute("x <- 10")
session$execute("x * 2")
}, sandbox = FALSE)
# With tools
result <- with_secure_session(
fn = function(session) {
session$execute("add(2, 3)")
},
tools = list(
securer_tool("add", "Add two numbers",
fn = function(a, b) a + b,
args = list(a = "numeric", b = "numeric"))
),
sandbox = FALSE
)
# }