R - Environment (Scope)

Card Puncher Data Processing

About

The scoping rules of a language determine how values are assigned to free variables (user variable) Free variables are not:

  • formal arguments
  • local variables (assigned inside the function body).

Closure

A function + an environment = a closure or function closure.

Hierarchy

Every environment has a parent environment; it is possible for an environment to have multiple “children” the only environment without a parent is the empty environment

Lexical scoping in R means that the values of free variables are searched for in the environment in which the function was defined.

If the value of a symbol is not found in the environment in which a function was defined, then the search is continued in the parent environment.

The search continues down the sequence of parent environments until we hit the top-level environment; this usually the global environment (workspace) or the namespace of a package.

After the top-level environment, the search continues down the search list until we hit the empty environment. If a value for a given symbol cannot be found once the empty environment is arrived at, then an error is thrown.





Discover More
Card Puncher Data Processing
R - (Datatype|Type|Storage Mode) of an object (typeof, mode)

In the C code underlying R, all objects are pointers to a structure with typedef SEXPREC; the different R data types are represented in C by SEXPTYPE, which determines how the information in the various...
Card Puncher Data Processing
R - Function

Functions are stored as R objects with the class function Functions can be: used as arguments of other functions nested where: arglist is a list of argument including the three dot argument....
Card Puncher Data Processing
R - Namespace

namespace function in R. See also



Share this page:
Follow us:
Task Runner