capture_env: Capture the environment of a function.

Description Usage Arguments Details Value

View source: R/capture_env.R

Description

Capture the environment of a function.

Usage

1
2
capture_env(local = FALSE, global_name = "captured_result",
  save_env = .GlobalEnv)

Arguments

local

A logical value, default FALSE, that decides if a locally captured environment should be assigned to some object in the local workflow, or if the function should be terminated and the result returned to the global workspace.

global_name

The name to be used when the function is terminated and the environment should be investigated in the global workspace.

save_env

The environment where the result should be assigned. Default value .GlobalEnv.

Details

This function can, when inserted into the body of another function, capture the environment at the inserted place. The rationale for this is to make it easier to hunt for errors or develop new code. attach and detach can be used on the captured environment in order to get hold of (or get rid of) the internal objects of the targeted function. This function can be used directly, but it might be more efficient to use the function under_construction (with the helpers uc_help and uc_help_call) instead, those functions will take care of a lot of the pesky details required to attaching and detaching the captured environments.

Value

This function clones the environment of the targeted function at the place of insertion. If local=TRUE, then the cloned environment will be returned to the internal work-flow of the function, the default is to create an object in the global workspace, named by global_name. Warning, be aware of the potential memory-problems that might occur if you attempt to store the temporary environment from several different steps in the function.


LAJordanger/UnderConstruction documentation built on May 3, 2019, 5 p.m.