Please use this tag for questions about using tidy evaluation within the tidyverse framework. For more information please refer to this handbook: https://tidyeval.tidyverse.org/
Questions tagged [tidyeval]
473 questions
12
votes
2 answers
Tidy evaluation programming and ggplot2
Trying to write a relatively simple wrapper to produce some plots, but can not work out how to specify tidy evaluation of grouping variables specified as ... an example function that facets variables but doesn't distinguish by grouping...
my_plot <-…

slackline
- 2,295
- 4
- 28
- 43
11
votes
1 answer
no visible binding for global variable ‘.’
I'm currently co-developing an R package using devtools. We use the
tidyverse %>% and associated purrr and dplyr packages within our
functions.
One of our functions is as follows (edited for clarity):
#' Print `cust_modl` object
#'
#' @param x A…

user4687531
- 1,021
- 15
- 30
11
votes
2 answers
R: Using a string as an argument to mutate verb in dplyr
I am building a shiny app which needs to allow users to define new variables for plotting. Specifically I want to allow users to define an expression to be used in mutate verb. The server receives the expression as text and I am wondering how to…

Sasha
- 5,783
- 8
- 33
- 37
10
votes
1 answer
How can you make tidyverse functions that support both quoted and unquoted arguments?
I know how to make functions that support quasi-quotation for an argument named 'variable' {using dplyr::enquo(variable) for unquoted function arguments} or functions that require you to quote the argument {using rlang::sym("variable")}. Is there an…

bholly
- 103
- 4
10
votes
3 answers
R How to use curly curly with filter or filter_?
I was answering this question where commenters suggested !!ensym, and I thought this might be a good place to use curly curly {{ but I couldn't get it to work (maybe not applicable?).
How might I do this filter operation, without using filter_,…

Arthur Yip
- 5,810
- 2
- 31
- 50
10
votes
2 answers
tidy eval vs base or get() vs sym() vs as.symbol()
I have been trying to understand tidy eval or how to use variables within tidyverse for a while, but I never seem to fully grasp it.
For example, I am trying to use ggplot with variable mappings. This would the base R version:
library(ggplot2)
var1…

burger
- 5,683
- 9
- 40
- 63
10
votes
1 answer
Variable not found with data mask
library(rlang)
myquo <- quo((Temp - 32) / 1.8)
eval_tidy(myquo, data = as_data_mask(datasets::airquality)) # works
e <- as_env(datasets::airquality, parent = global_env())
eval_tidy(myquo, data = as_data_mask(list(), parent = e)) # error
I…

F. Privé
- 11,423
- 2
- 27
- 78
10
votes
3 answers
How to loop over a tidy eval function using purrr?
I have the following data set (sample):
train <- data.frame(ps_ind_06_bin = c(FALSE, FALSE, FALSE, TRUE, TRUE, FALSE),
ps_ind_07_bin = c(FALSE, TRUE, TRUE, FALSE, TRUE, TRUE),
ps_ind_08_bin = c(TRUE,…

Ramiro Bentes
- 338
- 1
- 9
9
votes
1 answer
Get expression that evaluated to dot in function called by `magrittr` pipe
I have a function x_expression() which prints the expression passed to argument x.
pacman::p_load(magrittr, rlang)
x_expression <- function(x) {
print(enquo(x))
}
y <- 1
x_expression(y)
#>
#> expr: ^y
#> env: global
y %>%…

Rory Nolan
- 972
- 10
- 15
9
votes
1 answer
When to use rlang::ensym() over rlang::sym()?
I can see from the documentation that rlang::enquo() and rlang::quo() are used in different contexts. Hence, I used rlang::enysm() recently within a function declaration (see below). However, wrapped inside another SE function call, I got an…

Lorenz Walthert
- 4,414
- 1
- 18
- 24
9
votes
2 answers
dplyr 0.7 equivalent for deprecated mutate_
I cannot find in dplyr 0.7 a way to replace the mutate_ function which is going to be deprecated.
The mutate_ function is useful in my use case : I store in a database (string format) many instructions (that can be filtered if needed) and apply…

stephLH
- 131
- 7
9
votes
1 answer
Correct usage of dplyr::select in dplyr 0.7.0+, selecting columns using character vector
Suppose we have a character vector cols_to_select containing some columns we want to select from a dataframe df, e.g.
df <- tibble::data_frame(a=1:3, b=1:3, c=1:3, d=1:3, e=1:3)
cols_to_select <- c("b", "d")
Suppose also we want to use…

RobinL
- 11,009
- 8
- 48
- 68
8
votes
2 answers
Is it possible to pass multible variables to the same curly curly?
I am building a function that uses {{ }} (curly curly or double mustache)
I would like the user to be able to pass multiple variables into the same {{ }}, but I am not sure if this is possible using {{ }}. I can't find any examples showing how to do…

Steen Harsted
- 1,802
- 2
- 21
- 34
8
votes
1 answer
curly curly Tidy evaluation and modifying inputs or their names
The new curly curly method of tidy evaluation is explained in this article. Several examples are given demonstrating the use of this style of non-standard evaluation (NSE).
library(tidyverse)
# Example 1 --------------------------
max_by <-…

Display name
- 4,153
- 5
- 27
- 75
8
votes
1 answer
Using tidy eval for multiple dplyr filter conditions
I'm new to tidy eval and trying to write generic functions- one thing I'm struggling with right now is writing multiple filter conditions for categorical variables. This is what I'm using right now-
create_expr <- function(name, val){
…

Mridul Garg
- 477
- 1
- 8
- 17