mask_function2: Mask a function with given variables

Description Usage Arguments Value Examples

View source: R/language.R

Description

Modifies the default behavior of the function by adding one environment layer on top of input function. The masked variables are assigned directly to the environment.

Usage

1
mask_function2(f, ..., .list = list())

Arguments

f

any function

..., .list

name-value pairs to mask the function

Value

a masked function

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
a <- 123
f1 <- function(){
  a + 1
}
f1()   # 124

f2 <- mask_function2(f1, a = 1)
f2()   # a is masked with value 1, return 2

environment(f1)  # global env
environment(f2)  # masked env

env <- environment(f2)
identical(parent.env(env), environment(f1))  # true
env$a  # masked variables: a=1

dipsaus documentation built on Sept. 6, 2021, 5:08 p.m.