Skip to content
Prev 359566 / 398502 Next

How to make a function aware of its own call arguments

On 24/03/2016 10:28 AM, sbihorel wrote:
That's not quite true:  missing(x) works *before* x is altered within 
the function.  It works even if x has a default value.

So your myf2 could just use missing(c):

myf2 <- function(a=1, b=2, fun=NULL, c=myfun1(b,fun)){

    if (myf1(b,fun)>0 && missing(c)){
      c <- b
    }
    print(list(a,b,c))
}
The match.call() function does that, but I think you don't need that:

f <- function(x = 1, ...) {
   x <- 2
   match.call()
}
f(3)
## Prints:  f(x = 3)

Duncan Murdoch