Skip to content

How to use %>>% / perform side effects #72

Closed Answered by shikokuchuo
yogat3ch asked this question in Q&A
Discussion options

You must be logged in to vote

The deferred execution pipe %>>% requires the mirai to be assigned to a variable outside of the .() scope and a check for resolution by unresolved() or directly accessing the active binding b$data.

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

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yogat3ch
Comment options

Answer selected by yogat3ch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #71 on September 01, 2023 21:52.