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
有帮助吗?

解决方案

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)))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top