Learn R Programming

evaluate (version 1.0.1)

inject_funs: Inject functions into the environment of evaluate()

Description

Create functions in the environment specified in the envir argument of evaluate(). This can be helpful if you want to substitute certain functions when evaluating the code. To make sure it does not wipe out existing functions in the environment, only functions that do not exist in the environment are injected.

Usage

inject_funs(...)

Value

Invisibly returns previous values.

Arguments

...

Named arguments of functions. If empty, previously injected functions will be emptied.

Examples

Run this code
library(evaluate)
# normally you cannot capture the output of system
evaluate("system('R --version')")

# replace the system() function
old <- inject_funs(system = function(...) {
  cat(base::system(..., intern = TRUE), sep = "\n")
})

evaluate("system('R --version')")

# restore previously injected functions
inject_funs(old)

Run the code above in your browser using DataLab