Getting names from … (dots)

前端 未结 2 404
轮回少年
轮回少年 2021-01-02 20:28

In improving an rbind method, I\'d like to extract the names of the objects passed to it so that I might generate unique IDs from those.

I\'ve tried

相关标签:
2条回答
  • 2021-01-02 20:47

    Using the guidance here How to use R's ellipsis feature when writing your own function?

    eg substitute(list(...))

    and combining with 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)$...)}
    
    0 讨论(0)
  • 2021-01-02 20:49

    I picked this one up from Bill Dunlap on the R Help List Serve:

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

    I think this gives you what you want.

    0 讨论(0)
提交回复
热议问题