Examples for 'base::call'


Function Calls

Aliases: call is.call as.call

Keywords: programming attribute

### ** Examples

is.call(call) #-> FALSE: Functions are NOT calls
[1] FALSE
## set up a function call to round with argument 10.5
cl <- call("round", 10.5)
is.call(cl) # TRUE
[1] TRUE
cl
round(10.5)
identical(quote(round(10.5)), # <- less functional, but the same
          cl) # TRUE
[1] TRUE
## such a call can also be evaluated.
eval(cl) # [1] 10
[1] 10
class(cl) # "call"
[1] "call"
typeof(cl)# "language"
[1] "language"
is.call(cl) && is.language(cl) # always TRUE for "call"s
[1] TRUE
A <- 10.5
call("round", A)        # round(10.5)
round(10.5)
call("round", quote(A)) # round(A)
round(A)
f <- "round"
call(f, quote(A))       # round(A)
round(A)
## if we want to supply a function we need to use as.call or similar
f <- round
## Not run: call(f, quote(A))  # error: first arg must be character
(g <- as.call(list(f, quote(A))))
.Primitive("round")(A)
eval(g)
[1] 10
## alternatively but less transparently
g <- list(f, quote(A))
mode(g) <- "call"
g
.Primitive("round")(A)
eval(g)
[1] 10
## see also the examples in the help for do.call

[Package base version 4.2.3 Index]