Questions tagged [nse]

This tag covers questions about non-standard evaluation, which deals with the creation and manipulation of unevaluated expressions. This includes base R functions like call() and substitute(), as well as the more sophisticated tools provided by the rlang package. The latter are often also tagged with "tidyeval".

Non-Standard Evaluation (NSE) is a form of that focuses on the creation and manipulation of unevaluated expressions in . This is in contrast to Standard Evaluation (SE), where each expression encountered by the interpreter is immediately evaluated in its surrounding context. Using NSE tools, programmers can capture an expression and delay its evaluation, thus allowing the expression to reference variables and functions that may not yet exist when the expression is first defined. This is useful for parameterizing function calls, accessing data frame columns, and referencing variables, all with deferred interpretation.

Base NSE functionality in R is substantially extended by the package, which introduces the "immediate evaluation" operator !! and the ability to capture quosures, which consist of expressions along with their surrounding context.

Vignettes

Related tags

292 questions
0
votes
0 answers

Create conjunction of expressions from column list

I want to create a conjunction expression from a char vector. i.e. given a vector like c("a", "b", "c"). Ultimately I want to pass it to dplyr::filter Here is my attempt: makeNonNAConjunctionExpr = function(predictors) { # Given a char vector…
Sid
  • 420
  • 1
  • 6
  • 11
0
votes
0 answers

R: Parse (+eval) string used as args for subset/[. NSE case?

In my app user can provide "subsetting" expression (which consist of mix: variables, names stored in variable - vide args_input and subset_args_input variables) as arguments to subset/[ functions: df_data <- data.frame("a" = c(1,1,2), …
RSzT
  • 307
  • 3
  • 14
0
votes
2 answers

Mix dots and named arguments in function calling aes for ggplot2

I'm trying to create a wrapper around the ggplot that allows me to add some aesthetics like the x variable or color but always prefills y, ymin and ymax without having to work with quoted variable names. Since ggplot2 cannot use tidy evaluation I…
Robin Gertenbach
  • 10,316
  • 3
  • 25
  • 37
0
votes
0 answers

dplyr mutate use standard evaluation

I would like to reference in a dplyr mutate phrase to an object which includes the variable name in my data frame. How can I use standard evaluation in my case: Here is some dummy…
Fred
  • 35
  • 1
  • 3
0
votes
1 answer

passing column name as variable in dplyr

Variants of this question have been asked a lot, I also read about NSE. Still I cannot figure this out. This is easy: library(dplyr) data(cars) cars %>% group_by(speed) %>% summarise(d = mean(dist)) Now I want to use variable x to pass the…
juwi
  • 98
  • 7
0
votes
1 answer

How to mutate dataframe inside do with dplyr

Inside the do I am calling a mutate_ with reference to the original dataframe. The problem is that I can't get access to that dataframe inside the mutate. This has to do with lazyeval package, but I haven't been able to figure it out. Thank you…
Diego-MX
  • 2,279
  • 2
  • 20
  • 35
0
votes
3 answers

Forwarding expressions in dots after manipulation while capturing environment

I have a function fun_1 that utilizes substitute() on its ... argument, and another function fun_2 with signature fun_2(...) that implements the pattern do.call(fun_1, dots). I want fun_1() inside fun_2() to see the ... passed to fun_2(). Here's an…
kevinykuo
  • 4,600
  • 5
  • 23
  • 31
0
votes
1 answer

dplyr with string and NSE at same time

I like creating dplyr functions with character inputs, so will be very happy with new v0.6.0 coming up. For fun and learning current dplyr version 0.5.0.9004, i tried to make a flexible function that can take a character argument as well as an…
0
votes
0 answers

Conditionally quote/substitute an expression if not already quoted

I'm looking for a way to quote an argument passed to function (consider substitute(), ggplot2's aes(), subset() or data.table's [ behavior), but do it conditionally - only if not already quoted with quote(). This is because I'd like to easily chain…
mjktfw
  • 840
  • 6
  • 14
0
votes
1 answer

Function with dplyr and multiple statements

I am having trouble using several dplyr functions in one function, despite using the function variants. Example library(dplyr) # Data: mydf <- data.frame( var1 = factor(rep(1:24, each = 100)), var2 = runif(2400, min = -10, max = 125), …
Thorst
  • 1,590
  • 1
  • 21
  • 35
0
votes
0 answers

Standard evaluation inside a function with dplyr

I have data with lots of factor variables that I am visualising to get a feel for each of the variables. I am reproducing a lot of the code with minor tweaks for variable names etc. so decided to write a function to simply things. I just can't get…
davidhen
  • 579
  • 6
  • 10
0
votes
1 answer

string input to dplyr group_by

I need to understand how to input string values (NSE) in dplyr's group_by function. My data set and code below works fine with "group_by" but does not work with "group_by_" version. I am unable to find my mistake in this…
Shakir
  • 343
  • 5
  • 23
0
votes
1 answer

group_by and group_by_ in pipes

I am writing a function that can group and concatenate variables using the dplyr package: basket<-function(dataframe, group, target) { dataframe %>% group_by_(group) %>% summarise(new_target=paste(as.character(target),…
user95902
  • 149
  • 2
  • 3
  • 13
0
votes
0 answers

What is the way to use dplyr in the functions

I'd like to write a function that calculate a mean of a given variable with using dplyr function. I tried following concept with many modifications but were not succesful. Should one avoid dplyr functions within own functions? or is there any trick…
Mateusz1981
  • 1,817
  • 17
  • 33
0
votes
1 answer

How to pass a string as a parameter to a function which expects a variable in R

The first call to the function f works, the second does not. How can I pass a String ("v") to the function f so that the function works as exspected? library(data.table) f<-function(t,x)…
Funkwecker
  • 766
  • 13
  • 22
1 2 3
19
20