Open etiennebacher opened 4 years ago
Surprising, this seems to be the behavior of R's deparse
:
> deparse(quote(a + b))
[1] "a + b"
> deparse(quote(a := b))
[1] "`:=`(a, b)"
Oh, because :=
comes from rlang, not R. Errrrrgh... will have to think about this.
I completely forgot about this issue. I thought rlang::expr_deparse()
might do the trick but it doesn't seem to work with more complex expressions:
library(rlang)
expr_deparse(quote(a + b))
#> [1] "a + b"
expr_deparse(quote(a := b))
#> [1] "a := b"
lagged_name = "foo"
expr_deparse(dplyr::mutate(mtcars, !!lagged_name := lag(!!sym("mpg"))))
#> [1] "<df[,12]>"
My bad, the last expression should have been in quote()
:
library(rlang)
expr_deparse(quote(a + b))
#> [1] "a + b"
expr_deparse(quote(a := b))
#> [1] "a := b"
lagged_name = "foo"
expr_deparse(quote(dplyr::mutate(mtcars, !!lagged_name := lag(!!sym("mpg")))))
#> [1] "dplyr::mutate(mtcars, !!lagged_name := lag(!!sym(\"mpg\")))"
I don't know the internals of shinymeta
so can't help further, but I just wanted to correct my previous post
In the example below, the code given by
shinymeta
works but it is different of what I expected.mutate(!!lagged_name := lag(!!sym("mpg")))
mutate(`:=`(!!lagged_name, lag(!!sym("mpg"))))
Although the code obtained works, I'm worried it confuses the users when they try to see the code behind the shiny app. Is there a way to display infix operators in a more familiar way?
Not sure at all if this is the right place to post this, sorry if it's not (also asked on RStudio Community)