What is non-standard evaluation (NSE) in R, and where is it commonly used?

Quick Overview

Asks what non-standard evaluation is in R and where it appears in everyday code. Tests understanding of promises, substitute() and eval() in a data context, its uses in subset(), dplyr, model formulas and library(), and the problems it causes when you wrap these functions.

What is non-standard evaluation (NSE) in R, and where is it commonly used?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

What is non-standard evaluation (NSE) in R, and where is it commonly used? ```hint Two steps Separate what happens when an argument is captured from what happens when it is evaluated later, and ask in which environment each name gets looked up. ``` ```hint Familiar calls Think of everyday R calls where you type a column name or a package name without quotes and without a data frame prefix. ``` ### What a Strong Answer Covers - How R normally evaluates function arguments, and what NSE changes about that. - The mechanics: promises, the functions that capture expressions, and evaluation inside a data context. - Concrete places in base R and common packages where NSE appears. - What NSE costs when you program with these functions, and the tools that address it. ### Follow-up Questions - Why does wrapping `subset()` inside your own function break, and how would you write that wrapper with dplyr? - What are the differences between `{{ }}`, `!!` and the `.data` pronoun in tidy evaluation? - If a data frame has a column with the same name as a variable in your environment, which one does `dplyr::filter()` use, and how do you choose explicitly? - How do model formulas keep track of their environment, and when does that cause surprises?

Overview: Asks what non-standard evaluation is in R and where it appears in everyday code. Tests understanding of promises, substitute() and eval() in a data context, its uses in subset(), dplyr, model formulas and library(), and the problems it causes when you wrap these functions.

PracHub logo
General
Nov 24, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

What is non-standard evaluation (NSE) in R, and where is it commonly used?

What a Strong Answer Covers Guidance

  • How R normally evaluates function arguments, and what NSE changes about that.
  • The mechanics: promises, the functions that capture expressions, and evaluation inside a data context.
  • Concrete places in base R and common packages where NSE appears.
  • What NSE costs when you program with these functions, and the tools that address it.

Follow-up Questions Guidance

  • Why does wrapping subset() inside your own function break, and how would you write that wrapper with dplyr?
  • What are the differences between {{ }} , !! and the .data pronoun in tidy evaluation?
  • If a data frame has a column with the same name as a variable in your environment, which one does dplyr::filter() use, and how do you choose explicitly?
  • How do model formulas keep track of their environment, and when does that cause surprises?