Extract names of dataframes passed with dots

后端 未结 2 1491
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 03:27

One can use deparse(substitute()) combination to extract the parameter name inside the function like this function

names_from_dots <- functio         


        
相关标签:
2条回答
  • 2020-12-11 03:40

    You can try the following:

    names_from_dots <- function(...) sapply(substitute(list(...))[-1], deparse)
    
    names_from_dots(swiss, iris)
    # [1] "swiss" "iris" 
    
    0 讨论(0)
  • 2020-12-11 03:57

    I wouldn’t use substitute here at all, it works badly with ...1. Instead, you can just capture the unevaluated dots using:

    dots = match.call(expand.dots = FALSE)$...
    

    Then you can get the arguments inside the dots:

    sapply(dots, deparse)
    

    1 Part of the reason is, I think, that substitute does completely different things when called with (a) an argument (which is a “promise” object) or (b) another object. ... falls somewhere in between these two.

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