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
0
votes
0 answers
Tidy evaluation inside package and devtools::check() notes
Let's create a package, use dplyr and the magrittr pipe, and craft a new function:
usethits::create_package("TidyEvalInsidePackage")
usethis::use_package_doc()
usethis::use_package("dplyr")
usethis::use_pipe(export =…

pietrodito
- 1,783
- 15
- 24
0
votes
1 answer
Pull a column given as argument in function
I have a function that takes in a dataset and a variable as argument. It needs to filter based on some criteria, pull the column with name as variable and calculate its mean then. I am not able to pass the variable as column name though. Kindly…

FinRC
- 133
- 8
0
votes
2 answers
Check if object is Null or undefined
I have a function that includes an optional variable parameter. By default, I set the variable to NULL, but if it isn't NULL I'd like my function to do some stuff. I need a way to check if the variable is not null. This is complicated because I am…

Lief Esbenshade
- 793
- 4
- 13
0
votes
1 answer
Using character object to indicate column name within R's glue function?
I am trying to create a "label" column in my dataset using the glue::glue function. I want each row of this label column to include the value of a user-selected column. For example, using the mtcars dataset, I'd like to create a label column that…

Jake Scott
- 3
- 1
0
votes
1 answer
using `tidyeval` with the exposition pipe operator
I can't seem to figure out how to use the %$% operator from magrittr with tidyeval. Here is a minimally reproducible example of this problem:
table works with exposition operator outside tidyeval
library(magrittr)
print(mtcars %$% table(am))
#>…

Indrajeet Patil
- 4,673
- 2
- 20
- 51
0
votes
2 answers
tidyverse use across with pasted external vector that contains column names to mutate
Let's assume the following data:
df <- data.frame(x = c(1, 2),
y = c(3, 4),
z = c(5, 6))
Let's further assume I have a vector that contains column names I want to work on, e.g.
var_names_1 <- c("test", "x",…

deschen
- 10,012
- 3
- 27
- 50
0
votes
1 answer
Renaming column in tidyeval in dplyr 1.0
I wish to generate new columns based on receiving variables in tidy evaluation. For example,
library(dplyr)
some_custom_measure <- function(.data, cola, colb) {
.data %>% mutate("{{ cola }}_x_{{ colb }}" := {{ cola }} * {{ colb }})
}
iris %>%
…

ThomasJc
- 131
- 9
0
votes
1 answer
Create formulas from R dataframe of coefficients and variables
I am trying to create a function, formulator, to create R formulas out of a dataframe of responses, coefficients and constants and function names. My intent is to use it when converting large sheets of historical functions into useable R code. It is…

Silviculturalist
- 199
- 11
0
votes
1 answer
Using a data frame column name with glue_data
Hi I have a function in R:
myfunction<-function(.data, pvalue, roundto=2){
glue::glue_data(.x=.data,
"p={format(round(pvalue,digits=roundto),nsmall=roundto}")
}
This works fine when I pass .data$pvalue as pvalue to myfunction()
Ideally I would…

ab192
- 5
- 2
0
votes
1 answer
Using a tidyeval column after join
I have a function that joins data together, and then should take the average of a column.
Here I can join the data, but I am not sure how to average the x.x and x.y columns in a sufficiently generalized way
library(dplyr)
a <- tibble(id = 1:3, x…

John-Henry
- 1,556
- 8
- 20
0
votes
2 answers
Use quasiquotation for formula syntax in a user-created function?
When I run this code:
# Create example data
df <- tibble(age=rnorm(10),
income=rnorm(10))
make_model <- function(response_var, df){
# Create formula
form <- as.formula(response_var ~ .)
# Create model
model <- lm(form ,…

max
- 4,141
- 5
- 26
- 55
0
votes
1 answer
Curly curly passing a column name to mutate or regex_left_join returns error, could not find assignment operator `:=`
I am getting an error in console:
Error :=({ : could not find function ":="
I am using a fuzzyjoin (by David Robinson) and tidyverse packages only. The function is accepted with no syntax errors. On execution the error is thrown at me. What could…

Jacek Kotowski
- 620
- 16
- 49
0
votes
1 answer
as.formula function call where formula inputs are shiny reactive objects
This has been bugging me for ages.
I have a function where the first argument either needs to be of the form
function(data~ group_variable) OR of the form function(data, group = data$group_variable).
I have this function running smoothly in the…

Andrew McCartney
- 191
- 2
- 10
0
votes
2 answers
Using tidy evaluation to filter in my own function
I am having a hard time to use tidy evaluation when writing my own function.
I'll illustrate my problem using the ToothGrowth dataset, where we want to filter for e.g. VC as the…

portablemaex
- 115
- 6
0
votes
1 answer
How to print variable name from function argument using {{}} in R?
I am new to R and trying to understand functional Programming and use of {{}}.
I am not able to figure out how to just print the name of variable_name from argument without !!, enquos
I have tried below code but that doesn't work as…

ViSa
- 1,563
- 8
- 30