Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将字符作为R中函数的参数传递?_R - Fatal编程技术网

如何将字符作为R中函数的参数传递?

如何将字符作为R中函数的参数传递?,r,R,通常,我们可以在R中编写以下函数: testFunc <- function(a) {a} # This returns the value of a 我们如何以这种方式获取testFunc: argName <- 'a' testFunc <- function(argName) {a} # This does not work, since argName is required in this function. argName#创建不带参数的函数 testFu

通常,我们可以在R中编写以下函数:

testFunc <- function(a) {a} # This returns the value of a
我们如何以这种方式获取testFunc:

argName <- 'a'

testFunc <- function(argName) {a} # This does not work, since argName is required in this function.  
argName
#创建不带参数的函数

testFunc对于
a
作为
testFunc Hi Bowen Chen中的返回值意味着什么,是否要返回默认参数?如果是这样,formals会执行此formals(testFunc)$a
argName <- 'a'

testFunc <- function(argName) {a} # This does not work, since argName is required in this function.  
#create function without arguments
testFunc <- function() {a}

#add argument
argName <- 'a'
args <- alist(x = )
names(args) <- argName
formals(testFunc) <- args

testFunc
#function (a) 
#{
#  a
#}