Suppose I have a function like
z <- function(x, ...) { print(x) }
If ... missing, the function should do one thing; if indicated ... , the function should do something else with it. In this case, I can use missing(...) to detect the absence .. But I did not find an elegant way to detect using common methods such as [.Obj(x, ...) , where it is missing ... still pairlist(<emptyname>) and missing(...) = FALSE , even if I do not give values.
Here are some experiments:
z <- function(x, ...) { cat(missing(...)) } Obj <- function() { env <- environment() class(env) <- "Obj" env } `[.Obj` <- function(x,...) { cat(missing(...),"\n") }
With the code above, evaluate the following:
> z() TRUE > z(a=1) FALSE > Obj()[] FALSE NULL > Obj()[a=1] FALSE NULL
However, in debug mode for Obj()[] in RStudio, this is similar to
Browse[1]> list(...) Error: argument is missing, with no default Browse[1]> missing(...) [1] FALSE
Somehow, the way z() works does not work for Obj()[] . Is there an elegant way with a little overhead to determine if ... missing for the case of [.Obj(x, ...) that I really encounter?
See also: http://r.789695.n4.nabble.com/Arguments-passing-through-dot-dot-dot-lose-ability-to-check-for-missing-td4656455.html