Getting names from ... (periods)

When improving the rbind method rbind I would like to extract the names of the objects passed to it so that I can generate unique identifiers from them.

I tried all.names(match.call()) but this just gives me:

 [1] "rbind" "deparse.level" "..1" "..2" 

General example:

 rbind.test <- function(...) { dots <- list(...) all.names(match.call()) } t1 <- t2 <- "" class(t1) <- class(t2) <- "test" > rbind(t1,t2) [1] "rbind" "deparse.level" "..1" "..2" 

While I would like to get c("t1","t2") .

I know that in the general case it is impossible to get the names of the objects passed in the function, but it looks like ... it is possible that, as substitute(...) returns t1 in the above example.

+6
r
Sep 14
source share
2 answers

Using the manual How to use the ellipse function R when writing your own function?

eg substitute(list(...))

and combined with as.character

 rbind.test <- function(...) { .x <- as.list(substitute(list(...)))[-1] as.character(.x) } 

you can also use

 rbind.test <- function(...){as.character(match.call(expand.dots = F)$...)} 
+8
Sep 14 '12 at 1:16
source share

I selected this from Bill Dunlap in the R Serve help list :

 rbind.test <- function(...) { sapply(substitute(...()), as.character) } 

I think this gives you what you want.

+13
Sep 14 '12 at 2:20
source share



All Articles