call
Calling Functions
Description
Creates or tests for an object of mode call or call(...).
Usage
call(...)
is.call(x)
as.call(x)
Arguments
x |
any object.
|
... |
In call, the name of a function, as a string, followed by the arguments to it.
The arguments may be tagged, as in call("myFunction", argName = argValue).
|
Details
You can use call to have functions create other functions.
The d.order example below is a non-trivial example of this use.
d.order is a function that creates the density function of an
order statistic from a sample from a specific distribution.
Value
call | creates a call to the function named in the first argument, using the remaining
arguments as the arguments to the function call. |
is.call | checks whether x is a function call. |
as.call | tries to coerce x to a function call. |
See Also
Examples
funs <- c("sin", "cos")
x <- 30*pi/180
i <- 1
my.call <- call(funs[i], as.name("x"))
# my.call ready to be evaluated or put into an expression
eval(my.call)
is.call(my.call)
call_1 <- as.call(list(sin, quote(x)))
eval(call_1)
# d.order creates the density function of an order statistic.
d.order <- function(n, r, distfun, densityfun) {
f <- function(x) NULL
con <- exp(lgamma(n + 1) - lgamma(r) - lgamma(n - r + 1))
c1 <- as.call(list(substitute(distfun), as.name("x")))
c2 <- call("^", call("-", 1, c1), n - r)
c3 <- call("^", c1, r - 1)
c4 <- call("*", con, call("*", c2, call("*", c3,
as.call(list(substitute(densityfun), as.name("x"))))))
body(f) <- c4
f
}
d.median.norm.9 <- d.order(9, 5, pnorm, dnorm)
d.median.norm.9(-2:2)