Q: Change default arguments of a closure with a partial call

Description Usage Arguments Details Value Examples

View source: R/Q_function.R

Description

This function takes a partial call and returns a copy of the function in the call with default arguments replaced by the arguments in the partial call.

Usage

1
Q(.call, .quote = TRUE, .force = TRUE, .enclos = NULL)

Arguments

.call

A call object.

.quote

Logical; If TRUE, quotes the call argument.

.force

Logical; If TRUE, the arguments in the partial call are forced.

.enclos

The enclosing environment of the function. If NULL, the enclosing environment is not changed.

Details

The enclosing environment of the function is not changed by default, and changing it will typically break the function. The .force argument is set to TRUE by default, since the function will attempt to evaluate its default arguments in its enclosing context, where the supplied values are unlikely to exist.

Value

A new closure.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
   ## Play around with normals.
   ## Not run: dnorm2 = Q(dnorm(mean = 1, sd = 2))
   dnorm2(1) == dnorm(1, mean = 1, sd = 2)
   z = 1
   dnorm3 = Q(dnorm(mean = z, sd = 2))
   dnorm2(1) == dnorm(1, mean = z, sd = 2)

   ## Change plot.default to use type = "l" and lwd = 1.5 as default
   plot.default = Q(plot.default(type = "l"))
   par("lwd" = 1.5)
## End(Not run)

   ## Automatically add x to plots.

JonasMoss/SPQR documentation built on Oct. 30, 2019, 7:58 p.m.