Extract names of dataframes passed with dots

You can try the following:

names_from_dots <- function(...) sapply(substitute(list(...))[-1], deparse)

names_from_dots(swiss, iris)
# [1] "swiss" "iris" 

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.

Tags:

R

Ellipsis