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

Passing NSE to dplyr's filter

library(dplyr) specials <- names(mtcars)[1:2] specials[1] i=1 setup is complete, this works... mtcars %>% select_(specials[i], ~gear, ~carb) why does the nse fail on adding the filter? mtcars %>% select_(specials[i], ~gear, ~carb) %>% …
ben_says
  • 2,433
  • 4
  • 17
  • 18
0
votes
2 answers

R function to install missing packages

For one of my scripts I want to write an R function that checks if a package is already installed: if so it should use library() to import it in the namespace, otherwise it should install it and import it. I assumed that pkgname is a string and…
lucacerone
  • 9,859
  • 13
  • 52
  • 80
0
votes
1 answer

Apply row-wise Reduce with mutate_?

I have a dataframe with lots of columns, including four that represents sub-categories. data.frame(site_name=c("bla","blo","blu"), page_1=c(NA,NA,NA), page_2=c(NA,"detail_1","detail_2"), page_3=c("hello", "hola", NA), page_4=c(NA,NA,NA)) …
xav
  • 4,101
  • 5
  • 26
  • 32
0
votes
1 answer

ggvis inside a function

I try to create a simple function which allow to draw a ggvis plot. I know that I have to use non-standard evaluation here that's why I use intercept function of lazyeval package: test_fn <- function(data,xvar, yvar){ plot <- …
Nicolabo
  • 1,337
  • 12
  • 30
-1
votes
2 answers

Non standard evaluation in dplyr: how do you indirect a function's multiple arguments?

I'm trying to write a function that can pass either one or more arguments as variables to dplyr functions. I'd like to understand how to do it generally. Programming with dplyr doesn't seem to cover the issue and some of the more autoritative…
s_a
  • 885
  • 3
  • 9
  • 22
-2
votes
1 answer

How to save a calculation to a variable using variables that have not been defined yet?

Let's say I have a script, where I have a calculation like this: calculation = c( a*b + c*d + e*f ) And then in another script I want to call that calculation using the source…
Victor Nielsen
  • 443
  • 2
  • 14
1 2 3
19
20