this is a function which can't be changed:
foo <- function(y = 0, x = "no") {
print(x)
}
I never know how the argument to pass will be called. Here it is x
but sometimes it is a
and sometimes b
and so on... I get the information in variable argName
. So now argName = "x"
variable arg
which contains the argument to pass to the foo
function:
arg <- paste0(argName, "=\"yes\"")
now I want to pass arg
to the arguments of foo
to evaluate the same as:
foo(x="yes")
so how to do this? this was my tries:
foo(arg)
foo(`arg`)
foo('arg')
foo("arg")
foo(noquote(arg))
foo(noquote(`arg`))
foo(noquote('arg'))
foo(noquote("arg"))
foo(eval(arg))
foo(eval(noquote(arg))