【问题标题】:Inherit Roxygen2 documentation for multiple arguments in R package为 R 包中的多个参数继承 Roxygen2 文档
【发布时间】:2017-02-07 07:34:27
【问题描述】:

我正在编写一个 R 包,并希望将两个参数(例如 xy)的文档从旧函数(例如 old())继承到新函数 new()。不同的是,这两个参数共享相同的参数描述。也就是说,在old(), 函数中,它们被记录在一行中,并用逗号分隔,如下所示:

#' @param x,y Two arguments with the same description

我为new() 使用了以下参数来继承这些参数:

#' @inheritParams old

但是,当我构建包时,new() 的文档列出了 x 而不是 y

有没有办法像这样继承多个参数?

【问题讨论】:

    标签: r documentation roxygen2


    【解决方案1】:

    如果其他人偶然发现这一点,答案是你不能这样做。

    这来自 roxygen2 的创建者 Hadley Wickham。

    【讨论】:

      【解决方案2】:

      似乎在 6.1.1 版本中您可以使用,唯一的缺点是 new() 中的两个变量将具有相同的描述,但将单独列出。 为了以防万一,我试着写一个可重现的例子。

      # roxygen 6.1.1, devtools 2.0.1, usethis 1.4.0
      # Select a project folder and do setwd(<project_folder>)
      usethis::create_package("inheritanceTest")
      setwd("./inheritanceTest")
      
      t = "
      #' Hello
      #'
      #' @param x,y some stuff
      #'
      #' @return other stuff
      #' @export
      test_inherit_parent = function(x,y){
        print('Hello')
      }
      
      #' Hello2
      #'
      #' @inheritParams test_inherit_parent
      #'
      #' @return other stuff2
      #' @export
      test_inherit_child = function(x,y){
        print('Hello2')
      }
      "
      fileConn = file("./R/functions.R")
      writeLines(t, fileConn)
      close(fileConn)
      devtools::document()
      devtools::load_all(".")
      ?test_inherit_parent
      ?test_inherit_child
      

      【讨论】:

        猜你喜欢
        • 2017-11-28
        • 2014-10-08
        • 2013-09-24
        • 1970-01-01
        • 2019-11-22
        • 2014-10-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多