Accessing values
The values that were passed to a
function via the ellipsis construct can be access with
list(...)
within the function body.
s <- function (p1, ...) {
ret <- p1;
for (v in list(...)) ret <- ret + v;
return(ret);
}
s(10, 2, 9, 7);
#
# 28
Determining the names of the arguments
The names of the arguments that were passed can be determined with the
names(…)
function:
print_argument_names <- function (p1, ...) {
args <- list(...);
for (argName in names(args)) {
print(paste('Argument', argName, 'was passed with value', args[[argName]]));
}
}
print_argument_names(10, foo=1, bar='baz');
#
# Argument foo was passed with value 1
# Argument bar was passed with value baz