Questions tagged [tidyeval]

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/

473 questions
6
votes
4 answers

Remove columns the tidyeval way

I would like to remove a vector of columns using dplyr >= 0.7 library(dplyr) data(mtcars) rem_cols <- c("wt", "qsec", "vs", "am", "gear", "carb") head(select(mtcars, !!paste0("-", rem_cols))) Error: Strings must match column names. Unknown…
Scott
  • 161
  • 8
5
votes
2 answers

R dplyr programatically identify column

For some objects an attribute identifies a special column, for example the geometry column in an sf object. For conducting some calculations in dplyr it would be good to easily identify these columns. I'm searching for a way to create a function…
Bart
  • 1,267
  • 7
  • 18
5
votes
2 answers

How to inject weight into list of dplyr summarise name-value pairs?

I want to write a generalized weighted_summarise() function that will automatically parse and transform user-invoked function calls of the form: data %>% weighted_summarise(weights, a = sum(b), c = mean(d)) into an actual call that delegates to…
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
5
votes
1 answer

Problem programming with dplyr--column which is definitely a vector being picked up as a formula

I'm writing a function to reproduce several charts that will all have similar formatting (and other stuff) using highcharter. I want to be able select different columns of the data set should the names change or if I want to be doing something…
Ben G
  • 4,148
  • 2
  • 22
  • 42
5
votes
3 answers

curly curly tidy evaluation programming with multiple inputs and custom function across columns

My question is similar to this question but I need to apply a more complex function across columns and I can't figure out how to apply Lionel's suggested solution to a custom function with a scoped verb like filter_at() or a filter()+across()…
lost
  • 1,483
  • 1
  • 11
  • 19
5
votes
1 answer

Tidy Eval: Using {{var}} inside a nesting function not possible?

I was trying to use tidyr::complete inside my function while providing the variable names using {{}}. This works fine, however, when I add a nesting function to combine two variables I get an error. Please see the minimal example…
jpquast
  • 333
  • 2
  • 8
5
votes
1 answer

How can I use map* and mutate to convert a list into a set of additional columns?

I have tried probably hundreds of permutations of this code for literally days to try to get a function that will do what I want, and I have finally given up. It feels like it should definitely be doable and I am so close! I have tried to get back…
Francis Barton
  • 129
  • 2
  • 16
5
votes
1 answer

Tidyverse, Rlang and tidyeval: Bang bang (!!) failing inside function, but it appears to work without quotation

I am running a function on a long database (full_database) with two major groups where I need to perform various linear models on multiple subsets, per group. Then, I extract the R^2, the adjusted R^2 and the p.value into a dataframe where each row…
filcfig
  • 75
  • 3
5
votes
3 answers

How to use vector of column names as input into dplyr::group_by()?

I want to create a function based on dplyr that performs certain operations on subsets of data. The subsets are defined by values of one or more key columns in the dataset. When only one column is used to identify subsets, my code works…
kgolyaev
  • 565
  • 2
  • 10
5
votes
1 answer

How to test null or missing for enquos-type quosures

There's a quite subtle (and very confusing) distinction in rlang that... quosures are not quosure objects! In other terms: quo() and enquo() return a quosure quos() and enquos() return a quosureS, not a quosure (is_quosure(enquos(...)) returns…
Matifou
  • 7,968
  • 3
  • 47
  • 52
5
votes
1 answer

simple nested functions and dplyr tidyeval

library(tidyverse) set.seed(1) graph.data <- tibble(cal.date = as.Date(40100:40129, origin = "1899-12-30"), random_num = rnorm(30, 8, 5)) This is the data frame we're working with here. # A tibble: 30 x 2 cal.date random_num …
stackinator
  • 5,429
  • 8
  • 43
  • 84
5
votes
2 answers

Tidyeval: pass list of columns as quosure to select()

I want to pass a bunch of columns to pmap() inside mutate(). Later, I want to select those same columns. At the moment, I'm passing a list of column names to pmap() as a quosure, which works fine, although I have no idea whether this is the "right"…
Oliver
  • 1,098
  • 1
  • 11
  • 16
5
votes
2 answers

Tidyeval quo vs enquo

I stumbled upon this behaviour and do not quite understand it. Could someone, please, shed some light? I have written the following function which gives the following error: > MyFilter <- function(data, filtersVector) { filtersVector <-…
deann
  • 756
  • 9
  • 24
5
votes
2 answers

Using data.table and tidy eval together: why group by does not work as expected, why is ~ inserted?

I do not have a pressing use case but would like to understand how tidy eval and data.table may work together. I have working alternative solutions so I am mostly interested in the why because I hope to have a better understanding of tidy eval in…
Ildi Czeller
  • 190
  • 1
  • 9
5
votes
1 answer

How can I count the number of variables in an R quosure?

Let's say I have a function that takes in a data frame and a varying number of variables from that data frame using non-standard evaluation (NSE). Is there a faster/more straightforward way to count the number of provided variables than select()ing…
Jeffrey Girard
  • 761
  • 4
  • 20