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
Était-ce utile?

La 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)))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top