Search notes:

R function arguments: ellipsis

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
Github repository about-r, path: /function/arguments/ellipsis/access-values.R

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
Github repository about-r, path: /function/arguments/ellipsis/argument-names.R

See also

Function arguments

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758207261, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/function/arguments/ellipsis/index(78): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78