Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.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_Function_Arguments_Parameter Passing_Wrapper - Fatal编程技术网

如何避免在R中的包装函数中重新列出内部函数参数?

如何避免在R中的包装函数中重新列出内部函数参数?,r,function,arguments,parameter-passing,wrapper,R,Function,Arguments,Parameter Passing,Wrapper,假设我有一个具有许多参数的函数(例如,plot()) 我想通过围绕该函数创建一个包装函数来为该函数添加一些功能 随机示例: plot.new <- function() { windows(width = 10, height = 10) plot() } plot.new您可以使用 plot.new它们是否需要出现在两个参数列表位置?如果“重用”一个参数名(或选择仅定义一个内部函数参数),会发生什么情况?例如:plot.new最后一个问题:我可以将省略号放在包装函数参数列表中

假设我有一个具有许多参数的函数(例如,
plot()

我想通过围绕该函数创建一个包装函数来为该函数添加一些功能

  • 随机示例:

    plot.new <- function() {
      windows(width = 10, height = 10)
      plot()
    }
    
    plot.new您可以使用


    plot.new它们是否需要出现在两个参数列表位置?如果“重用”一个参数名(或选择仅定义一个内部函数参数),会发生什么情况?例如:
    plot.new最后一个问题:我可以将省略号放在包装函数参数列表中的任何位置吗?例如:
    函数(…,z)
    vs
    函数(z,…)
    ?如果是这样的话,如果我在运行包装器函数时选择不命名参数,这会表明参数的“顺序”吗?
    plot.new <- function(...) {
      windows(width = 10, height = 10)
      plot(...)
    }
    
    plot.new <- function(x, ...) {
        graphics.off() #OPTIONAL
        windows(width = 10, height = 10)
        plot(x = x, ...)
    }
    
    #USAGE
    plot.new(x = rnorm(10), y = rnorm(10), pch = 19)