[Rd] Expanding partial names

hadley wickham h.wickham at gmail.com
Tue Mar 7 18:31:24 CET 2006


Here's a slightly different approach:

lowlevel <- function(longname = 1, ...) {
  cat("longname = ", longname, "\n")
}

wrapper <- function(...) {
  newargs <- defaults(list(...), list(longname = 2))
  do.call("lowlevel", newargs)
}

defaults <- function(x, defaults)  {
	if (length(x) == 0) return(defaults)
	names(x) <- ifelse(is.na(pmatch(names(x), names(defaults))),
names(x), names(defaults))
	c(x, defaults[setdiff(names(defaults), names(x))])
}

wrapper()
wrapper(longname=20)
wrapper(long=20)
wrapper(junk=3)


Hadley



More information about the R-devel mailing list