Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

documentation - Recommended approach to documenting S4 classes in R package

Following the example from R packages by Hadley Wickham and Jenny Bryan. I'm looking at suggested approach to generating documentation using roxygen2 for S4 objects. The example, which is available in section 10.7.2, reads:

Document S4 classes by adding a roxygen block before setClass(). Use @slot to document the slots of the class in the same way you use @param to describe the parameters of a function. Here’s a simple example:

#' An S4 class to represent a bank account.
#'
#' @slot balance A length-one numeric vector
Account <- setClass("Account",
  slots = list(balance = "numeric")
)

Results

If followed this generates two documentation files with identical content. Formally speaking, there is the Account object and Account class described in Account-class.

enter image description here

Considerations

It makes sense to have the Account object as it can be easily to used to create new instances of that class. However, I find that having one documentation entry only available as Account-class would be sufficient.

Solution attempts

Adding #' @rdname Account-class or #' @name Account-class to Account-class still results in two documentation entry being generated.

Questions

  1. Is there a practical reason why the one may need two identical documentation entries one Classname and another Classname-class with identical content?
  2. What's a good approach to document S4 classes using roxygen2 with files named Classname-class.R and also creating objects Classname <- setClass()? In the desired scenario the following would happen:
    • New class is defined Newclass-class.R file
    • The class definition is of format Newclass <- setClass("Newclass", ...
    • the roxygen tags available in that file result in only one documentation entry: Newclass-class being created

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...