

R is unable to find the disp variable because it exists as a column in the mtcars dataset, not in the evaluation environment. Standard evaluation in R would find the disp variable and compute the division, so let’s try that: disp / 61.0237 #> Error in eval(expr, envir, enclos): object 'disp' not found The mutate function is calculating disp / 61.0237 and saving the result as a column called displ_l. As an example, let’s look at the dplyr code above. So what is non-standard evaluation? As the name may suggest, it is code which is evaluated in a non-standard way. Mutate(displ_l = disp / 61.0237) library(ggplot2) Try to identify the NSE parts in the following code examples: library(dplyr)

Most tidyverse packages also leverage NSE to simplify the typing needed to transform a dataset or plot some data. In fact, NSE is used each time you load in a package without quoting the package name. You may not know what non-standard evaluation is, but you have definitely used it before (perhaps without even realising). In the loop, R tries to be helpful by loading pkg instead of the value stored inside (“ggplot2”, and then “dplyr”).įor most R users, an understanding of non-standard evaluation (NSE) is rarely needed. That is what allows you to use library(tidyverse) instead of library("tidyverse"). If it were that simple, it wouldn’t warrant a blog post! This doesn’t work because the library function uses non-standard evaluation. So to load packages in a loop, one might try: packages Error in library(pkg): there is no package called 'pkg' Most R users would load packages using the library function, such as library(tidyverse). If you really want have fun, try loading packages in a loopĪlthough not a pop-quiz, it is certainly a challenge, and a common cause of confusion for R users. As part of this discussion, podcast guest Roger Peng ( noted that:

In Nick Tierney ( and Saskia Freytag’s ( second Credibly Curious podcast, they briefly delve into the confusing world of non-standard evaluation (NSE).
