通常,我们可以在R中编写以下函数:
testFunc <- function(a) {a} # This returns the value of a
如此
testFunc(1)
1
我们如何以这种方式获取testFunc:
argName <- 'a'
testFunc <- function(argName) {a} # This does not work, since argName is required in this function.
答案 0 :(得分:1)
#create function without arguments
testFunc <- function() {a}
#add argument
argName <- 'a'
args <- alist(x = )
names(args) <- argName
formals(testFunc) <- args
testFunc
#function (a)
#{
# a
#}