[R] documenting R reference class methods with roxygen2

Ben Tupper btupper at bigelow.org
Wed Jul 20 15:07:57 CEST 2016


Hi,

Yes, it takes a lot of searching for find out how to use roxygen with Ref Classes.  Thank goodness for Hadley Wickham's book ( http://r-pkgs.had.co.nz/ ).

For a Ref Class methods are actually documenting NULL, and you need to add the "@name Classname_Methodname" tag.  Otherwise, documentation is similar to that for functions.

#' Title
#'
#' Other stuff
#'
#' @name MyClass_fooey
#' @param foo_value numeric blah blah blah
#' @return numeric
#' @examples{
#'	\dontrun{
#'		blah blah blah
#'      }
#' }
NULL
MyClass$methods(
	fooey = function(foo_value = 3){
	    cat("in the fooey method\n")
	    return(foo_value)
	})

You could scout out some of the examples here ... https://github.com/BigelowLab/flowcamr 


Cheers,
Ben


> On Jul 20, 2016, at 4:26 AM, Witold E Wolski <wewolski at gmail.com> wrote:
> 
> I would like to document function arguments in R reference classes and
> I do not know how.
> 
> I know that methods description can be provided by adding
> a string below the function declaration. But how to document the
> function arguments in similar fashion like the arguments of R
> functions (which can be documented with @param).
> 
> Thank you.
> 
> PS. Sorry if for some this question is off topic but I did not found a
> mailing list dedicated to roxygen2.
> 
> 
> 
> -- 
> Witold Eryk Wolski
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Report Gulf of Maine jellyfish sightings to jellyfish at bigelow.org or tweet them to #MaineJellies -- include date, time, and location, as well as any descriptive information such as size or type.  Learn more at https://www.bigelow.org/research/srs/nick-record/nick-record-laboratory/mainejellies/



More information about the R-help mailing list