An environment describes a (scoped) mapping of names to their definitions (EnvironmentMemory).

First, yes, R stores its environments differently, potentially even with another differentiation between the baseenv, the emptyenv, and other default environments (see https://adv-r.hadley.nz/environments.html). Yet, during the dataflow analysis, we want sometimes to know more (static reference information) and sometimes know less (to be honest, we do not want that, but statically determining all attached environments is theoretically impossible --- consider attachments by user input).

One important environment is the BuiltInEnvironment which contains the default definitions for R's built-in functions and constants. Please use initializeCleanEnvironments to initialize the environments (which includes the built-ins). During serialization, you may want to rely on the builtInEnvJsonReplacer to avoid the huge built-in environment.

  • define - to define a new identifier definition within an environment
  • resolveByName - to resolve an identifier/name to its definitions within an environment
  • makeReferenceMaybe - to attach control dependencies to a reference
  • pushLocalEnvironment - to create a new local scope
  • popLocalEnvironment - to remove the current local scope
  • appendEnvironment - to append an environment to the current one
  • overwriteEnvironment - to overwrite the definitions in the current environment with those of another one
interface REnvironmentInformation {
    current: IEnvironment;
    level: number;
}

Implemented by

Properties

Properties

current: IEnvironment

The currently active environment (the stack is represented by the currently active IEnvironment#parent). Environments are maintained within the dataflow graph.

level: number

nesting level of the environment, will be 0 for the global/root environment