From h.wickham at gmail.com  Tue Mar  7 18:31:24 2006
From: h.wickham at gmail.com (hadley wickham)
Date: Tue, 7 Mar 2006 11:31:24 -0600
Subject: [Rd] Expanding partial names
In-Reply-To: <440DA2E4.4030508@stats.uwo.ca>
References: <440D9295.7090207@stats.uwo.ca>
	<971536df0603070642y295f4c64l74fb3e5d67b1605e@mail.gmail.com>
	<440DA2E4.4030508@stats.uwo.ca>
Message-ID: <f8e6ff050603070931s590c916m6f8de408cb2b287d@mail.gmail.com>

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



[Rd] Expanding partial names
hadley wickham