如何使用Roxygen2正確記錄S4類插槽? - How to properly document S4 class slots using Roxygen2?

問題:

For documenting classes with roxygen(2), specifying a title and description/details appears to be the same as for functions, methods, data, etc. However, slots and inheritance are their own sort of animal. 對於使用roxygen(2)記錄類,指定標題和描述/細節似乎與函數,方法,數據等相同。但是,插槽和繼承是它們自己的動物類型。 What is the best practice -- current or planned -- for documenting S4 classes in roxygen2? 在roxygen2中記錄S4類的最佳實踐 - 當前或計劃的最佳實踐是什麼?

Due Diligence: 盡職調查:

I found mention of an @slot tag in early descriptions of roxygen. 我在早期的roxygen描述中發現了一個@slot標籤。 A 2008 R-forge mailing list post seems to indicate that this is dead, and there is no support for @slot in roxygen: 2008年的R-forge郵件列表帖子似乎表明這已經死了,而且@slot在roxygen中沒有支持:

Is this true of roxygen2? roxygen2是真的嗎? The previously-mentioned post suggests a user should instead make their own itemized list with LaTeX markup. 前面提到的帖子建議用戶應該使用LaTeX標記創建自己的逐項列表。 Eg a new S4 class that extends the "character" class would be coded and documented like this: 例如,擴展"character"類的新S4類將被編碼並記錄如下:

#' The title for my S4 class that extends \code{"character"} class.
#'
#' Some details about this class and my plans for it in the body.
#'
#' \describe{
#'    \item{myslot1}{A logical keeping track of something.}
#'
#'    \item{myslot2}{An integer specifying something else.}
#' 
#'    \item{myslot3}{A data.frame holding some data.}
#'  }
#' @name mynewclass-class
#' @rdname mynewclass-class
#' @exportClass mynewclass
setClass("mynewclass",
    representation(myslot1="logical",
        myslot2="integer",
        myslot3="data.frame"),
    contains = "character"
)

However, although this works, this \\describe , \\item approach for documenting the slots seems inconsistent with the rest of roxygen(2), in that there are no @ -delimited tags and slots could go undocumented with no objection from roxygenize() . 然而,儘管這個作品,這個\\describe\\item用於記錄的插槽做法似乎與roxygen其餘不一致(2),在不存在@ -delimited標籤和插槽也從沒有異議去無證roxygenize() It also says nothing about a consistent way to document inheritance of the class being defined. 它也沒有說明記錄正在定義的類的繼承的一致方法。 I imagine dependency still generally works fine (if a particular slot requires a non-base class from another package) using the @import tag. 我想通過使用@import標記,依賴仍然可以正常工作(如果特定插槽需要來自另一個包的非基類)。

So, to summarize, what is the current best-practice for roxygen(2) slots? 總而言之,目前roxygen(2)插槽的最佳實踐是什麼?

There seem to be three options to consider at the moment: 目前似乎有三種選擇:

  • A -- Itemized list (as example above). A - 分項列表(如上例所示)。
  • B -- @slot ... but with extra tags/implementation I missed. B - @slot ...但是有額外的標籤/實施我錯過了。 I was unable to get @slot to work with roxygen / roxygen2 in versions where it was included as a replacement for the itemized list in the example above. 我無法讓@slot在版本中使用roxygen / roxygen2作爲上述示例中逐項列表的替代。 Again, the example above does work with roxygen(2). 同樣,上面的例子確實適用於roxygen(2)。
  • C -- Some alternative tag for specifying slots, like @param , that would accomplish the same thing. C - 用於指定插槽的替代標記,如@param ,可以完成相同的操作。

I'm borrowing/extending this question from a post I made to the roxygen2 development page on github . 我正在從github上的roxygen2開發頁面發佈的帖子中借用/擴展這個問題。


解決方案:

參考一: https://stackoom.com/question/Uuow
參考二: How to properly document S4 class slots using Roxygen2?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章