How to check if any arguments were passed via "..." (ellipsis) in R? Is missing(...) valid? How to check if any arguments were passed via "..." (ellipsis) in R? Is missing(...) valid? r r

How to check if any arguments were passed via "..." (ellipsis) in R? Is missing(...) valid?


Here's an alternative that will throw an error if you try to pass in a non-existent object.

test2 <- function(...) if(length(list(...))) FALSE else TRUEtest2()#[1] TRUEtest2(something)#Error in test2(something) : object 'something' not foundtest2(1)#[1] FALSE


I think match.call is what you need:

test <- function(...) {match.call(expand.dots = FALSE)}> test()test()> test(x=3,y=2,z=5)test(... = list(x = 3, y = 2, z = 5))

It will give you every time the values passed in the ellipsis, or it will be blank if you won't pass any.

Hope that helps!


If it helps anyone I ended up using the following function to get the ellipsis parameters for every function (returns an empty list or a list of arguments):

get.params <- function (...) {  params <- list()  if (length(list(...)) && !is.null(...))     params <- unlist(...)  return(params)}

for:

f <- function(t, ...) { params <- get.params(...) print(paste(params))}