On 6/1/07, Mike Meredith <[EMAIL PROTECTED]> wrote:
>
>
> Thanks very much to all of you. It looks like 'match.call' is the key, and
> both Brian's and Gabor's solutions work fine. --- Mike.

Brian's is shorter but I think the one in my post is a bit more robust:

> f1 <- function(...) {
+    m <- as.list(match.call(expand.dots=TRUE))[-1]
+    nm <- names(m)
+    for(i in seq_along(m)) if(!nchar(nm[i])) nm[i] <- deparse(m[[i]])
+    nm
+ }
>
> f2 <- function(...) {
+ x <- list(...)
+ if (is.null(names(x))) names(x) <- ""
+ names(x)[names(x) == ""] <- NA
+ mc <- match.call()[-1]
+ ifelse(is.na(names(x)), as.character(mc), names(x))
+ }
>
> f1(sin, cos)
Error in if (!nchar(nm[i])) nm[i] <- deparse(m[[i]]) :
        argument is of length zero
> f2(sin, cos)
[1] "sin" "cos"

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to