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
0
votes
1 answer

Giving user defined functions non-quoted arguments in purrr

I'm learning quasiquotation and quotation with rlang. My function looks at if any forbidden_values occur in any of the mentioned dataframe variables selectlist, and marks a row with any positive result as 1, else 0. How can I make rlang interpret…
0
votes
1 answer

How to use tidy eval NSE to expand a `an expression`

I want to expand the !!! expression just like they do in dplyr-verbs e.g. aggregate_expressions <- list(n = quote(n())) do_something(iris, !!!(aggregate_expressions)) and say I want do_something to perform do_something <- function(...) { iris…
xiaodai
  • 14,889
  • 18
  • 76
  • 140
0
votes
1 answer

Writing a custom case_when function to use in dplyr mutate using tidyeval

I'm trying to write a custom case_when function to use inside dplyr. I've been reading through the tidyeval examples posted in other questions, but still can't figure out how to make it work. Here's a reprex: df1 <- data.frame(animal_1 = c("Horse",…
Harry M
  • 1,848
  • 3
  • 21
  • 37
0
votes
1 answer

R - function paramter that is list of functions--inspect parameter without evaluating?

EDIT: the initial resonses suggest my write-up focused people's attention on questions of best practices rather than questions of technique. I'd like to focus on a technical issue, however, with the below just as a toy example: If a person passes a…
Joe
  • 119
  • 5
0
votes
1 answer

Deploying arrange(desc(.)) on each variable passed previously via enquos

Background Using rlang I've a simple summary function for dplyr that counts a number of missing observations within a variable per provided groups. I would like to return the results in a descending order of grouping variables. Sample…
Konrad
  • 17,740
  • 16
  • 106
  • 167
0
votes
2 answers

Tidyeval: apply function to data frames extracted from list

This is a simplified version of a problem involving a large list containing complex tables. I want to extract the tables from the list and apply a function to each one. Here we can create a simple list containing small named data…
DSH
  • 427
  • 2
  • 10
0
votes
3 answers

How to specify a column name in ddply via character variable?

I have a tibble/dataframe with sample_id condition state --------------------------------- sample1 case val1 sample1 case val2 sample1 case val3 sample2 control val1 sample2 …
Rohit Farmer
  • 319
  • 4
  • 15
0
votes
4 answers

substitute LHS in `=` operator with rlang tidyeval inside Sys.setenv

Problem description Sys.setenv does not have an easy interface to supply LHS (the env var name) as a parameter. If one wants to dynamically define what env var should be set, then metaprogramming approach is required. Base R way This small helper…
jangorecki
  • 16,384
  • 4
  • 79
  • 160
0
votes
1 answer

Using tidyeval's braces with a dplyr::group_by

I wanted to pass a vector of strings to purrr::map to generate a list of tables. library(tidyverse) library(magrittr) names(mtcars) %>% extract(8:10) %>% map( function(i) mtcars %>% group_by({{i}}) %>% tally ) but…
tomw
  • 3,114
  • 4
  • 29
  • 51
0
votes
1 answer

Patch function which calls .Call

My goal is to patch the rlang::eval_tidy function. In its original form it only calls .Call: eval_tidy <- function(expr, data = NULL, env = caller_env()) { .Call(rlang_eval_tidy, expr, data, env) } In my case it should behave different for one…
Querenker
  • 2,242
  • 1
  • 18
  • 29
0
votes
1 answer

Iterate Group_by across Dataframe in R

I'm trying to simplify a current piece of code in my script. I want to group by each possible combination of two categorical variables and summarise a mean value of my explanatory variable. Example using mpg database found in…
JmezR
  • 3
  • 2
0
votes
2 answers

mutate_ deprecated, easy and understandable alternatives?

I'm trying to create a function that creates a variable. Like this: Add_Extreme_Variable <- function(dataframe, variable, variable_name){ dataframe %>% group_by(cod_station, year_station) %>% mutate(variable_name= ifelse(variable >…
Chris
  • 2,019
  • 5
  • 22
  • 67
0
votes
3 answers

How does filter() in dplyr evaluate what's inside the () in a customized function?

I am trying to write a function that takes two column names and upper and/or lower boundary for each column names, so that that way I can subset the data with column names and boundary of my choice. Using mtcars as an example, if I want to subset…
xiahfyj
  • 101
  • 1
  • 5
0
votes
4 answers

Refer a column by variable name

Sample data dat <- data.frame(Sim.Y1 = rnorm(10), Sim.Y2 = rnorm(10), Sim.Y3 = rnorm(10), obsY = rnorm(10), ID = sample(1:10, 10), ID_s = rep(1:2, each = 5)) For the following vector, I want to calculate the…
89_Simple
  • 3,393
  • 3
  • 39
  • 94
0
votes
1 answer

Applying functions stored in a dataframe to another dataframe in R

I am dealing with a situation wherein I have multiple, distinct data sets with different column names, but the functions to be applied to them are similar. I thought, to reduce code duplication, I could create another dataset of column names, and…
info_seekeR
  • 1,296
  • 1
  • 15
  • 33