R: explanation of frames, substitute and deparse

Viewed 33

I'm working my way through the R theory and struggling to fully understand the basic concept of R.

For this, I set myself the goal to extract the name of the variable that is passed as the function argument arg1. That is,

fun  <- function (arg1) {
  ...
}
a <- 1:5
fun(a) # should  return "a"

After hours of trying I've the following solution:

deparse (substitute(arg1, sys.frame(1))

However, I cannot really explain whats going on here. Could someone give me an clear explanation of what the sys.frame, substitute and deparse function does? The official documentation does not really help me :/

0 Answers
Related