You are here

Working with functions that use dot-dot-dot

Blog tags: 

I'm having some trouble converting this handy script that generates multicollinearity examples into a respectable use of ....

Main problem is that I can't figure how to prevent the "double specification" of options. The ... gets resolved and so sometimes
an option is repeated.

The more I read on this, the more I suspect that I need to collect two argument lists, then use the R function modifyList to
make the options unique. THen instead of running persp(...) I use "do.call("persp", myCleanListOfArgs).

######
Mark Schwartz., r-help, 20061130

Try this:

test <- function(x, ...)
{
print(x)
dotargs <- list(...)
if ("y" %in% names(dotargs)) print(dotargs$y)
if ("z" %in% names(dotargs)) print(dotargs$z)
}

> test(4)
[1] 4

> test(4, y = 2)
[1] 4
[1] 2
#######

http://stackoverflow.com/questions/5890576/usage-of-in-functions

Richie Cotton:

f <- function(x, ...)
{
dots <- list(...) #1
if(length(dots) == 0) return(NULL)
cat("The arguments in ... are\n")
print(dots)
f(...) #2
}

f(1,2,3,"a", list("monkey"))

The function, f, stores all but the first input argument in the ellipsis variable. For accessing its contents, it is easiest to convert it to a list (1). The main use however is for passing arguments to subfunctions, which requires no conversion (2).

########################

Why sometimes

input_list <- list(...)

and other times:

object <- as.list(substitute(list(...)))[-1L]

http://stackoverflow.com/questions/3057341/how-to-use-rs-ellipsis-featur...

###############

User login