Function Calls

DESCRIPTION:
Creates or tests for an object of mode "call" or "call(...)".

USAGE:
call(NAME, ...)
is.call(x)
as.call(x)

REQUIRED ARGUMENTS:
NAME:
character string naming the function to be called.

x:
any object.

OPTIONAL ARGUMENTS:
...:
arguments to the function.

VALUE:
call creates a call to the named function, 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.


DETAILS:
The as.call function is generic; currently there are no methods written for it.

One use of call is in functions that create other functions. The d.order example below is a non-trivial example; d.order is a function that creates the density function of an order statistic from a sample from a specific distribution.


SEE ALSO:
do.call , as.name , eval

EXAMPLES:
funs <- c("sin", "cos")
my.call <- call(funs[which], as.name("x"))
# my.call ready to be evaluated or put into an expression
eval (my.call)

# function that 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 <- call(substitute(distfun), as.name("x")) c2 <- call("^", call("-", 1, c1), n - r) c3 <- call("^", c1, r - 1) c4 <- call("*", con, call("*", c2, call("*", c3, call(substitute( densityfun), as.name("x"))))) f[[length(f)]] <- c4 f } d.median.norm.9 <- d.order(9, 5, pnorm, dnorm) d.median.norm.9(-2:2)