Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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中有以下功能: tst <- function(x,y){ foo <- match.call() print(foo) } tst(4,5) 这将打印tst(x=4,y=5,6),这非常好。但是,我需要添加一个参数name,以便函数知道如何处理它。例如,我希望它是tst(x=4,y=5,z=6)。我只是尝试了foo[[length(foo)+1]]实际上,您可以将调用视为一个列表,并给它一个命名参数: > tst = function(x,y){ fo

假设我在R中有以下功能:

tst <- function(x,y){
  foo <- match.call()
  print(foo)
}

tst(4,5)

这将打印tst(x=4,y=5,6),这非常好。但是,我需要添加一个参数name,以便函数知道如何处理它。例如,我希望它是
tst(x=4,y=5,z=6)
。我只是尝试了
foo[[length(foo)+1]]实际上,您可以将调用视为一个列表,并给它一个命名参数:

> tst =
function(x,y){
 foo = match.call()
 foo[["this"]] ="that"
 print(foo)
}
> tst(x=2,y=3)
tst(x = 2, y = 3, this = "that")

为什么需要
调用
输出?你打算如何使用它?从一开始就得到一份清单不是更好吗?这源于一个问题。我想修改答案以包含
nls
。与给定答案中的
lm
nls
不同,
nls
需要额外的参数,如
start
。因此,在
mysmooth
函数中,我想添加这些参数。
> tst =
function(x,y){
 foo = match.call()
 foo[["this"]] ="that"
 print(foo)
}
> tst(x=2,y=3)
tst(x = 2, y = 3, this = "that")