lobstr
lobstr copied to clipboard
Request: make `ast()` not automatically unwrap quosures
I was using rlang::blast()
, and trying to understand how it works.
lazyeval::ast_()
shows the actual call:
blast <- function(expr, env = caller_env()) {
eval_bare(enexpr(expr), env)
}
exp <- quo(a + b)
f <- function(x) {
lazyeval::ast_(sys.call())
invisible()
}
blast(f(!!exp))
#> ┗ ()
#> ┗ `f
#> ┗ ()
#> ┗ `~
#> ┗ ()
#> ┗ `+
#> ┗ `a
#> ┗ `b
However lobstr::ast(!!x)
unwraps the quosures so you don't see the actual call:
g <- function(x) {
lobstr::ast(!!sys.call())
invisible()
}
blast(g(!!exp))
#> █─g
#> └─█─`+`
#> ├─a
#> └─b
Actually, now that I think if it, I think that it's a little confusing that both lazyeval::ast_
and lobstr::ast
do some sort of quosure unwrapping. The actual call has a quosure object inlined the AST, but both of those functions obscure that fact. It would be helpful if the ast
function did not automatically do that, because it is misleading -- I want to see the actual AST to understand what's going on, not a modified version of it.
h <- function(x) {
sys.call()
}
z <- blast(h(!!exp))
z[[2]]
#> <quosure>
#> expr: ^a + b
#> env: global
Is this a duplicate of #27?
I think it's not quite the same -- what I'm asking for here is for quosures to not be specially printed (because currently, they're magically hidden), but #27 is asking for them to be specially printed. But I think the overall goal is the same, which is to see quosures in the AST and understand them.