How can I document an R class?

How can I document the use of member functions of a reference class?

if I write an Rd file with a \usage block, how can I avoid WARNING

 Functions/methods with usage in documentation object 'XmlDoc' but not in code: $ new 

I expect the \usage block to allow me to write things like:

 obj <- ClassName$new(par1, par2, ...) obj$method1(oth1, ...) 

and then I will document the parameters in the \arguments block.

If I do, the R CMD check complains about

 Assignments in \usage in documentation object 'ClassName': 

and does not recognize methods as code objects, I need a document.

at the moment I am writing Rd files without the \usage block and writing the above code to the \examples block, but then I have nowhere to document the arguments, and thus check has very little to actually check. Since I am not satisfied with this, I am now asking the community about current general practice.

+6
source share
2 answers

I do not know if this is correct, but what I did is the Methods section, and then describe the method documentation in the interior.

+5
source

If I understood correctly, the Reference Classes methods are S4, therefore, it documents the S4 classes and methods .

to make this answer a little more self-contained, here is what I do with the Logger class in the logging.oo package.

this is the code i wanted to document with some omissis [...].

 Logger <- setRefClass("Logger", fields=list(name = "character"), methods=list( setLevel = function(newLevel) { [...] }, getLevel = function() { [...] }, addHandler = function(...) { [...] }, 

this is the corresponding contents of the .Rd files:

 \alias{\S4method{new}{Logger}} \alias{\S4method{setLevel}{Logger}} \alias{\S4method{getLevel}{Logger}} \alias{\S4method{addHandler}{Logger}} [...] \usage{ \S4method{new}{Logger}(name) \S4method{setLevel}{Logger}(newLevel) \S4method{getLevel}{Logger}() \S4method{addHandler}{Logger}(...) 

while in the NAMESPACE file I simply indicate that I am exporting the Logger class, I do not specify its methods: they are all automatically exported.

+4
source

Source: https://habr.com/ru/post/893137/


All Articles