The R language has a nifty feature for defining functions that can take a variable number of arguments. For example, the function data.frame
takes any number of
This works as expected. The following is an interactive session:
> talk <- function(func, msg, ...){
+ func(msg, ...);
+ }
> talk(cat, c("this", "is", "a","message."), sep=":")
this:is:a:message.
>
Same, except with a default argument:
> talk <- function(func, msg=c("Hello","World!"), ...){
+ func(msg, ...);
+ }
> talk(cat,sep=":")
Hello:World!
> talk(cat,sep=",", fill=1)
Hello,
World!
>
As you can see, you can use this to pass 'extra' arguments to a function within your function if the defaults are not what you want in a particular case.