Questions tagged [quasiquotes]
70 questions
8
votes
3 answers
Why is the @ sign needed in this macro definition?
In the following when macro:
(defmacro when (condition &rest body)
`(if ,condition (progn ,@body)))
Why is there an "at" @ sign?

Luke
- 5,771
- 12
- 55
- 77
7
votes
1 answer
dplyr function with optional grouping only when argument provided
I need to write a dplyr function that creates a customised area plot. So here's my attempt.
area_plot <- function(data, what, by){
by <- ensym(by)
what <- ensym(what)
data %>%
filter(!is.na(!!by)) %>%
group_by(date, !!by) %>%
…

Kuba_
- 886
- 6
- 22
5
votes
2 answers
What does !! operator mean in R
Can anybody explain, please, what for do we need !!, !!! or {{}} operators from rlang? I tried to learn more about quasiquotation but did not get anything.
I've reached several posts on curly-curly operator on Stack and understood that we use {{…

rg4s
- 811
- 5
- 22
5
votes
4 answers
Why is it possible to use unquote-splicing on a non-list at the end of a quasiquoted list?
The quasiquoted list `(1 ,@2 3) is invalid because 2 is not a list. However, `(1 2 ,@3) is valid and will return a dotted list: (1 2 . 3). I observe this result in Common Lisp and Scheme. Why is it possible to use unquote-splicing for non-lists at…

Flux
- 9,805
- 5
- 46
- 92
5
votes
1 answer
Passing quasiquoted arguments within nested functions
Below I've written a simple function snafu() that calculates a new variable snafu_var.
library(dplyr)
df <- mtcars %>% select(am, cyl) %>% slice(1:5)
snafu <- function(data, var1, var2){
require(dplyr)
var1 <- enquo(var1)
var2 <-…

Joe
- 3,217
- 3
- 21
- 37
4
votes
2 answers
tidyr use glue strings later in function
Tidy eval now supports glue strings
So this works great:
my_summarise5 <- function(data, mean_var ) {
data %>%
mutate(
"mean_{{mean_var}}" := mean({{ mean_var }}),
)
}
mtcars %>% my_summarise5(cyl)
But then
my_summarise5 <-…

daaronr
- 507
- 1
- 4
- 12
4
votes
1 answer
Haskell: Making Quasi-Quoted values strict / evaluated at compile-time
I have a 'Month' type, which is roughly
newtype Month = Month Word8
where the Month constructor isn't exported; instead, a function
mon :: Word8 -> Maybe Month
mon i = if i > 0 && i < 13
then Just $ Month i
else Nothing
is…

user3416536
- 1,429
- 9
- 20
4
votes
4 answers
using `rlang` quasiquotation with `dplyr::_join` functions
I am trying to write a custom function where I use rlang's quasiquotation. This function also internally uses dplyr's join functions. I have provided below a minimal working example that illustrated my problem.
# needed libraries…

Indrajeet Patil
- 4,673
- 2
- 20
- 51
4
votes
2 answers
Quasiquotation with data.table
I'm trying to wrap my head around quasiquotation so that I could use it together with a data.table call. Here is an example:
library(data.table)
library(rlang)
dt <- data.table(col1 = 1:10, col2 = 11:20)
dt[, col1]
If I wanted to wrap this into…

JBGruber
- 11,727
- 1
- 23
- 45
4
votes
2 answers
Non-standard evaluation and quasiquotation in dplyr() not working as (naively) expected
I am trying to search a database and then label the ouput with a name derived from the original search, "derived_name" in the reproducible example below. I am using a dplyr pipe %>%, and I am having trouble with quasiquotation and/or non-standard…

Josh
- 1,210
- 12
- 30
4
votes
1 answer
class of expr and exprs are different in rlang in R ! Why?
I am not sure if this has been asked here, But I am very confused here. I am reading this awesome book called Advanced R by Hadley Wickham from here.
There is function called cement that has been described here, I have modified it little bit and…

PKumar
- 10,971
- 6
- 37
- 52
3
votes
1 answer
Using rlang double curly braces {{ in data.table
Problem
The {{}} operator from the rlang package makes it incredibly easy to pass column names as function arguments (aka Quasiquotation). I understand rlang is intended to work with tidyverse, but is there a way to use {{}} in data.table?
Intended…

rafa.pereira
- 13,251
- 6
- 71
- 109
3
votes
1 answer
Quasiquotes escaping
I would like to add my new language to Haskell using the Quasiquotes, but the language itself uses |] as a keyword.
Is there some way, how to:
a) Escape |], so it is passed to my language
b) Let the parser of my language decide, when the…

Přemysl Šťastný
- 1,676
- 2
- 18
- 39
3
votes
1 answer
mockery::mock and mockery::stub do not work properly with quasiquotation?
I've written an import function that gets a single file from an aws s3-bucket.
That function itself is a wrapper around aws.s3::s3read_using() which takes a reading function as its first argument.
Why do I wrap around aws.s3::s3read_using() ?…

y3kMyRon
- 71
- 7
3
votes
1 answer
How can I get the string of Haskell code (along with the value)
I'd like to get both the string and value of arbitrary Haskell code. For example:
f (1+1) -> (2,"1+1")
The reason I want to do this is because I'm writing a programming language and I'd like to provide an option to interpret the code (for fast…

Darren Smith
- 207
- 1
- 4