substitute.parameters: Substitute parameters in a function with values

Description Usage Arguments Details Examples

Description

Replace variables in func with values given in params. Remove argument names from func if necessary.

Usage

1
substitute.parameters(func, params = as.list(environment(func)))

Arguments

func

a function or expression

params

a list of the form list(param1=value1,param2=value2,...) with values to substitute the parameters. Defaults to the variable list in the current environment.
Hint: the values may also be quote()ed R expressions. See examples.

Details

This is a convenient wrapper around the base function substitute extended by the possibility to substitute values in a function, possibly removing arguments of the function according to which variables are to be replaced with values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# a simple function
f <- function( a, b, c ) a + b + c

substitute.parameters( f, list( a = 1 ) )
# a is replaced by 1, the function looses the argument a
# function (b, c) 
# 1 + b + c

substitute.parameters( f, list( a = quote(b) ))
# a is replaced with b, the function looses the argument a
# function (b, c) 
# b + b + c

a = 10 # Set global value for a
substitute.parameters( f ) # no params argument given
# By default, params are taken from the environment of f
# function (b, c) 
# 10 + b + c

nobodyinperson/functionutils documentation built on May 23, 2019, 9:31 p.m.