[R] Documenting a function using roxygen2

G.Maubach at weinwolf.de G.Maubach at weinwolf.de
Tue Oct 11 13:13:33 CEST 2016


Hi All,

I began to document my functions using roxygen2. This is an example of a 
function I would like to write for training and testing purposes:

t_simple_table <- function(variable,
                           useNA = TRUE,
                           print = FALSE) {
    #' @title Create a simple table for one variable.
    #'
    #' @description t_simple_table() creates absolute and relative 
    #' frequencies, cumulative sums and column sums for both as well as
    #' overall statistics about valid N and missing values.
    #' 
    #' 
    #' @param variable (vector, list, data.frame): variable the table is
    #' created for.
    #' @param useNA (logical): flag to include or exclude missing values
    #' from the computation.
    #' @param print (logical): flag to print/not print a table before
    #' returning it as an object.
    #' 
    #' @operation
    #' Coerces the given variable to a factor.
    #' If useNA = TRUE NA is also transformed to a valid value,
    #' if useNA = FALSE it is disregarded in all operations.
    #' 
    #' @return Returns a table with the following statistics:
    #' 
    #' <Variable Name> Frequencies   Percent   Cumulative
    #'                                         Percent
    #' Valid                     .         .
    #' Missing                   .         .
    #' Total                     .       100
    #' Categories
    #'   Cat 1                   .         .            .
    #'   Cat 2                   .         .            .
    #'   Cat 3                   .         .            .
    #'   ...                     .         .          100
    #'   Total                   .       100
    #'
    #' @errorhandling None
    #' 
    #' @version "0.1"
    #' 
    #' @created "2016-10-11"
    #' @updated "2016-10-11"
    #' 
    #' @status development
    #'
    #' @see Manderscheid: Sozialwissenschaftliche Datenanalyse mit R, 
    #' p. 79ff
    #'
    #' @author Georg
    #'
    #' @license GPL-2
 
# function body to be defined

}

Is this a correct header for a function?

How could I do better?

Kind regards

Georg



More information about the R-help mailing list