Question

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
Was it helpful?

Solution

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)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top