Pass the name of the object to the do.call () function

Is there a way to pass the name of the object to the 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
+4
source share
1 answer

You want to use alistin your appeal to do.call.

alistprocesses its arguments as if they were describing the arguments of a function. Values ​​are not evaluated.

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

or you can use quote

do.call(what="PrintObjectName", args=list(obj=quote(iris)))
+6
source

Source: https://habr.com/ru/post/1524637/


All Articles