Named arguments and defaults. ``...''

As first noted in §[*] if arguments to called functions are given in the ``name=object'' form, they may be given in any order. Furthermore the argument sequence may begin in the unnamed, positional form, and specify named arguments after the positional arguments.

Thus if there is a function fun1 defined by

fun1 <- function(data, data.frame, graph, limit) [function body omitted]

Then the function may be invoked in several ways, for example

ans <- fun1(d, df, 20, T)

ans <- fun1(d, df, graph=T, limit=20)

ans <- fun1(data=d, limit=20, graph=T, data.frame=df)

are all equivalent.

In many cases arguments can be given commonly appropriate default values, in which case they may be omitted altogether from the call when the defaults are appropriate. For example, if fun1 were defined as

fun1 <- function(data, data.frame, graph=T, limit=20) ...[*]

it could be called as

ans <- fun1(d, df)

which is now equivalent to the three cases above, or as

ans <- fun1(d, df, limit=10)

which changes one of the defaults.

It is important to note that defaults may be arbitrary expressions, even involving other arguments to the same function; they are not restricted to be constants as in our simple example here.

Another frequent requirement is to allow one function to pass on argument settings to another. For example many graphics functions use the function par() and functions like plot() allow the user to pass on graphical parameters to par() to control the graphical output. (See §[*] for more details on the par() function.) This can be done by including an extra argument, literally ``...'', of the function, which may then be passed on. An outline example is given in Figure [*].


 
Figure:   Use of the ellipsis argument, ``...''
\begin{figure}
\hrule\medskip
\begin{verbatim}
fun1 <- function(data, data.frame...
 ...ar(pch=''*'', ...)

 [more omissions]
 }\end{verbatim}\medskip\hrule\end{figure}



Jeff Banfield
2/13/1998