© Thomas Mailund 2017

Thomas Mailund, Functional Programming in R, 10.1007/978-1-4842-2746-6_3

3. Scope and Closures

Thomas Mailund

(1)Aarhus N, Denmark

A scope is something functions or expressions are associated with that tells them what values variables refer to. It is used to figure out which environment expressions are evaluated in. The same variable name can be used many places in a program, but the scope of an expression tells R exactly which variable of a given name is referred to in the expression.

A closure is a function with an associated scope. All functions in R have at least two different environments where they can find out what value a given variable is referring to. There is the local environment of the function, where function parameters ...

Get Functional Programming in R: Advanced Statistical Programming for Data Science, Analysis and Finance now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.