質問

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