Reputation: 5
Normally, we can write a following function in R:
testFunc <- function(a) {a} # This returns the value of a
such that
testFunc(1)
1
How can we get the testFunc in this way:
argName <- 'a'
testFunc <- function(argName) {a} # This does not work, since argName is required in this function.
Upvotes: 0
Views: 121
Reputation: 132676
#create function without arguments
testFunc <- function() {a}
#add argument
argName <- 'a'
args <- alist(x = )
names(args) <- argName
formals(testFunc) <- args
testFunc
#function (a)
#{
# a
#}
Upvotes: 1