Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 212038

How to save a `quosure` to be used in another session?

$
0
0

What's the best way to save a quosure so that it can be run on another session?

Consider the below, which uses the {rlang}'s quosure concept to quote an expression x+2 and captures its environment which is global and evaluates it to 4.

However, if you save the quosure and then start a fresh session, then eval_tidy no longer works because x may be undefined in the new environment.

My use-case is saving these expressions and running them in a separate session. What's the best way to save a quosure so that it can be run on another session? Is the only way to save the environment as well? This is not ideal as the environment may contain very large objects, so it's best if there is a lighter weight solution.

library(rlang)

x = 2

quo_x_plus_2 = quo(x + 2)


saveRDS(quo_x_plus_2, "plsdel.rds")

# quits R
q()


a = readRDS("plsdel.rds")

rlang::eval_tidy(a)

Viewing all articles
Browse latest Browse all 212038

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>