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
1
vote
2 answers
Using dataframe name as a column in a model table
I'm confused as to why the following doesn't work. I'm trying to use the name of a data frame/tibble as a column in a multiple models data frame, but keep running up against the following error. Here's an…

David Pepper
- 593
- 1
- 4
- 14
1
vote
1 answer
Passing (function) user-specified column name to dplyr do()
Original question
Can anyone explain to me why unquote does not work in the following?
I want to pass on a (function) user-specified column name in a call to do in version 0.7.4 of dplyr. This does seem somewhat less awkward than the older standard…

stephematician
- 844
- 6
- 17
1
vote
2 answers
Generate tibbles with different column names with map2()
I have a character vector of names and a list of numeric vectors. I would like to create tibbles with one column each where the column names come from the character vector and the should be populated with the values from the numeric vectors.
Here is…

der_grund
- 1,898
- 20
- 36
1
vote
2 answers
How can I pass a variable through a quoted expression into a function that returns a function using that value?
Here's an example:
library(ggplot2)
library(scales) # for percent() function
custom_percent <- function(n){
function(x){
return(paste(percent(x), sprintf('(%d)', round(x* (n)))))
}
}
mydata = data.frame(x = rep(c('a','b','c'),…

Max Candocia
- 4,294
- 35
- 58
1
vote
2 answers
how to update a dataframe in a purrr loop?
Consider this simple example
library(dplyr)
library(purrr)
mydata <- dplyr::data_frame('value' = c(1,2,3))
> mydata
# A tibble: 3 x 1
value
1 1.
2 2.
3 3.
I have a function that takes the dataframe and a number as arguments, and…

ℕʘʘḆḽḘ
- 18,566
- 34
- 128
- 235
1
vote
2 answers
Mutate with tidy evaluation
Using mutate_() I used to provide a list of new variables and the logic needed to create them.
library(dplyr)
library(rlang)
list_new_var <-
list(new_1 = "am * mpg",
new_2 = "cyl + disp")
mtcars %>%
mutate_(.dots = list_new_var) %>%
…

kputschko
- 766
- 1
- 7
- 21
1
vote
1 answer
tidyr quasiquotation with lexical scoping
I realize that tidy evaluation does not use lexical scoping, but I want the quasiquotation in rlang to look for symbols in the environment I decide.
Current behavior:
envir <- new.env(parent = globalenv())
eval(parse(text = "little_b <- 'b'"), envir…

landau
- 5,636
- 1
- 22
- 50
1
vote
2 answers
Using quotation to programmatically create a S3 generic
I want to create an S3 generic in the global environment from a function. I took a look at R.methodsS3::setGenericS3.default and came up with the following:
create_generic <- function(nm) {
src <- sprintf("%s <- function(obj, ...)…

alexpghayes
- 673
- 5
- 17
1
vote
0 answers
using non-standard evaluation with formula Bis
Non-Standard evaluation in R. I want to send a formula to a function that uses lm.
I have a data frame with one response: y and many predictors. I will fit a model inside a function. The function will receive a filtering criteria as a string and…

Harlan Nelson
- 1,394
- 1
- 10
- 22
1
vote
1 answer
Constructing lists using tidyeval tools (like `!!` and `:=`)
I am looking a way for easy list constructing based on R's tidyeval framework as defined in the rlang package.
Below is what I want to achieve:
a <- "item_name"
b <- "item_value"
identical(
list(!!a := !!b), # list(!!a := b) is of course also…

sztal
- 287
- 2
- 10
1
vote
3 answers
Using dplyr `enquo` after calling argument
I have a function that roughly follows this structure:
TestFunc <- function(dat, point) {
if (!(point %in% c("NW", "SE", "SW")))
stop("point must be one of 'SW', 'SE', 'NW'")
point <- enquo(point)
return(dat %>% filter(point…

Brandon Sherman
- 673
- 1
- 8
- 25
1
vote
2 answers
How do you specify of possible arguments states in functions using non-standard evaluation?
I am learning about programming with tidy evaluation and non-standard evaluation and have been trying to work out how to constrain the possible states of an argument in a function.
For instance given a data set:
set.seed(123)
data <-…

G_T
- 1,555
- 1
- 18
- 34
1
vote
2 answers
lapply function with arguments for dataframe and variable
I have a custom function which summarises a variable. I simplified the function to illustrate my problem, i.e. it is more complex than shown below. Note that the general structure of the function should remain the same: It takes an argument for…

piptoma
- 754
- 1
- 8
- 19
1
vote
4 answers
dplyr 0.7 tidy eval: convert character variables to factors
I have a dataset with many variables, some of them are character variables, which I would like to convert to factors. Since there are many variables to convert, I would like to do this using the new tidy eval functionality from dplyr_0.7. Here is a…

der_grund
- 1,898
- 20
- 36
1
vote
3 answers
Computing total rank for multiple columns using NSE syntax
My goal is to write a function take_by_rank that
can operate on arbitrary selection of numeric columns within a data frame;
uses non-standard evaluation like base::subset or dplyr verbs;
understands the minus sign naturally, so that -foo means "the…

tonytonov
- 25,060
- 16
- 82
- 98