How to use %>>%
/ perform side effects
#72
-
Hi library(mirai)
env <- new.env()
mirai::.(
mirai::mirai({
Sys.sleep(5)
TRUE
}) %>>%
assign(x = "test", envir = env)
)
Sys.sleep(6)
env$test I've pored over the documentation for far too long now and just can't make sense of how to use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The deferred execution pipe So for you example above: library(mirai)
env <- new.env()
m <- mirai({
Sys.sleep(5)
TRUE
})
b <- .(m %>>% assign(x = "test", envir = env))
Sys.sleep(6)
if (!unresolved(b)) env$test However if you only care about the side effect (performing the assignment to the environment) rather than using the return value, then using mirai promises and a different pipe may be a better fit. For example: library(mirai)
library(promises)
library(mirai.promises)
env <- new.env()
mirai({
Sys.sleep(5)
TRUE
}) %...>% assign(x = "test", envir = env)
Sys.sleep(6)
env$test |
Beta Was this translation helpful? Give feedback.
The deferred execution pipe
%>>%
requires themirai
to be assigned to a variable outside of the.()
scope and a check for resolution byunresolved()
or directly accessing the active bindingb$data
.So for you example above:
However if you only care about the side effect (performing the assignment to the environment) rather than using the return value, then using mirai promises and a different pipe may be a better fit. For example: