What are closures in R? Provide an example of their use and explain their benefits.
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Overview: Asks what a closure is in R, for a working example of one, and why closures are useful. Tests understanding of function environments, function factories, keeping state with the superassignment operator, and the pitfalls that come with captured variables.