Pregunta

Is there a way to pass object name into do.call() function?

For example:

#First make a function that will return the name of object itself.
PrintObjectName <- function(obj){
  print(deparse(substitute(obj)))
}

data(iris)

PrintObjectName(iris)
[1] "iris" #This is what I want

do.call(what="PrintObjectName", args=list(obj=iris))
#The output is a messy stuff
¿Fue útil?

Solución

You want to use alist within your call to do.call.

alist handles its arguments as if they described function arguments. So the values are not evaluated

do.call(what="PrintObjectName", args=alist(obj=iris))
# [1] "iris"

or you could use quote

do.call(what="PrintObjectName", args=list(obj=quote(iris)))
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top