capture_parse_eval_side_effects: Capture side effects from parse eval

View source: R/side_effects.R

capture_parse_eval_side_effectsR Documentation

Capture side effects from parse eval

Description

Wraps string in capture_side_effects() before parsing and evaluating it. The side effects (error, warnings, messages) are returned in a list.

When capturing an error, no other side effects are captured.

Usage

capture_parse_eval_side_effects(
  string,
  envir = NULL,
  copy_env = FALSE,
  reset_seed = FALSE,
  disable_crayon = TRUE
)

Arguments

string

String of code that can be parsed and evaluated in envir.

envir

Environment to evaluate in. Defaults to parent.frame().

copy_env

Whether to use deep copies of the environment when capturing side effects. (Logical)

Disabled by default to save memory but is often preferable to enable, e.g. when the function alters non-local variables before throwing its error/warning/message.

reset_seed

Whether to reset the random state on exit. (Logical)

disable_crayon

Whether to disable crayon formatting. This can remove ANSI characters from the messages. (Logical)

Value

named list with the side effects.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

See Also

Other capturers: capture_side_effects()

Examples

# Attach package
library(xpectr)


capture_parse_eval_side_effects("stop('hi!')")
capture_parse_eval_side_effects("warning('hi!')")
capture_parse_eval_side_effects("message('hi!')")


xpectr documentation built on Nov. 18, 2022, 5:10 p.m.