【问题标题】:Create function with arguments of another function in R使用 R 中另一个函数的参数创建函数
【发布时间】:2012-12-13 11:56:53
【问题描述】:

我创建了一个函数Dummyfunc,它计算不同样本的倍数变化。 我在这个Dummyfunc 函数中使用gsva 函数。我想从我的Dummyfunc 访问gsva 函数的所有参数,以便我可以根据需要更改参数的值。 到目前为止,我已经尝试过这样做:-

Dummyfunc <- function(method="gsva",verbose=TRUE,kernel=){
gsva(method=method,kernel=kernel,verbose=verbose)
}

但它可以以自动化方式完成,以便可以从Dummyfunc 访问gsva 函数的所有参数

【问题讨论】:

    标签: r function arguments


    【解决方案1】:

    我不太确定你想要什么,但我想使用...。例如:

    Dummyfunc = function(...)
         gsva(...)
    

    Dummyfunc = function(method="gsva", verbose=TRUE, ...)
         gsva(method=method, verbose=verbose, ...)
    

    我们使用... 传递任何其他参数。

    【讨论】:

      【解决方案2】:

      如果我正确理解您的问题,您应该使用... 将它们全部传递,您可能会将它们全部写出来,但这可能需要一段时间。

      # define the internal function
      f.two <- 
          function( y , z ){
              print( y )
              print( z )
          }
      
      # define the external function,
      # notice it passes the un-defined contents of ... on to the internal function
      f.one <-
          function( x , ... ){
              print( x )
      
              f.two( ... )
      
          }
      
      # everything gets executed properly
      f.one( x = 1 , y = 2 , z = 3 )      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-13
        • 2021-05-02
        • 1970-01-01
        • 2015-05-29
        • 1970-01-01
        • 2023-03-22
        相关资源
        最近更新 更多