Skip to content

3. Coding guide: roxygen2

Emanuel Huber edited this page Oct 18, 2019 · 2 revisions

Feel free to contact me if you have any troubles, questions, comments, wishes, etc.

emanuel.huber@alumni.ethz.ch

Functions

Minimal documentation

#' Title
#'
#' Description
#'
#' Details
#' @param parameter1 [\code{character(1)}]
#'                   Description parameter1.
#'                   Default: 1
#' @param parameter2 [\code{numeric}]
#'                   Description parameter2
#'                   Default: 100.100.
#' @return A nice value
#' examples
#' sum(1:10)
#' sum(.Machine$integer.max, 1L)
#' \dontrun{
#' sum("a")
#' }
myFunction <- function(..., na.rm = TRUE){}

Arguments (@param) and return (@return)

Adapted from rdatsci Style-Guide

A scalar integer parameter

#' @param n [\code{integer(1)}]
#'          My argument.
#'          Default: 1

An integer vector of arbitrary size

#' @param x [\code{integer}]
#'          Recorded data.

An S3 object of a class you defined in the same package.

#' @param obj [\code{GPR-class}]
#'            An object of the class GPR.

Data type for returned object.

#' @return [\code{integer(1)}]
#'         Returns the length of the vector.

Adapted from source, see also checkMate package:

type defined length undefined length
any type [\coed{any}]
logical vector [\code{logical(n)}] [\code{logical}]
integer vector [\code{integer(n)}] [\code{integer}]
numeric vector [\code{numeric(n)}] [\code{numeric}]
complex vector [\code{complex(n)}] [\code{complex}]
character vector [\code{character(n)}] [\code{character}]
raw vector [\code{raw(n)}] [\code{raw}]
factor ?? ??
undefined matrix [\code{matrix(m,n)}] [\code{matrix}]
logical matrix [\code{logical matrix(m,n)}] [\code{logical matrix}]
numeric matrix [\code{numeric matrix(m,n)}] [\code{numeric matrix}]
undefined array [\code{array(n1,n2,n3,...)}] [\code{array}]
logical array [\code{logical array(n1,n2,n3,...)}] [\code{logical array}]
numeric array [\code{numeric array(n1,n2,n3,...)}] [\code{numeric array}]
list [\code{list(n)}] [\code{list}]
pairlist ?? ??
data frame [\code{data.frame(m,n)}] [\code{data.frame}]
formula - [\code{formula}]
expression - [\code{expression}]
function - [\code{function}]
class object - [\code{ClassName-class}]

Class

#' Class Title
#' 
#' Description: An S4 class to represent a ground-penetrating radar (GPR) data.
#'
#' Details concerning the class = TODO
#' @slot version [\code{character(1)}]
#'               version of RGPR
#' @slot data [\code{matrix(m,n)}]
#'            Matrix whose columns correspond to GPR traces 
#' @name GPR-class
#' @rdname GPR-class
#' @export
setClass(
  Class="GPR", 
  ...

S4 Method & Generic

Generic

#' @name CMPAnalysis
#' @rdname CMPAnalysis-methods
#' @exportMethod CMPAnalysis
setGenericVerif("CMPAnalysis", function(x, method = c("semblance", 
               "winsemblance", "wincoherence", "wincoherence2"), v = NULL, 
               asep = NULL, w = NULL) standardGeneric("CMPAnalysis"))

Method

#' Common mid-point (CMP) analysis
#' 
#' either use 'rec' and 'trans' to compute the distance between the antennas
#' or give the distance between the antennas (asep)
#' or seq(x@antsep, by = x@dx, length.out = length(x))
#'
#' Details...
#' @param x [\code{GPR-class}]
#'          An object of the class \code{GPR}
#' @param method A length-one character vector 
#' @rdname CMPAnalysis-methods
#' @aliases CMPAnalysis,GPR-method
#' @export
setMethod("CMPAnalysis", "GPR", function(x, method = c("semblance", 
                                         "winsemblance",   "wincoherence", 
                                         "wincoherence2"), v = NULL, 
                                         asep = NULL, w = NULL){
  ...

Aliases

#' Basic arithmetical functions
#'
#' 
#' @param e1 An object of the class RGPR.
#' @param e2 An object of the class RGPR.
#' @examples
#' data(frenkeLine00)
#' A <- exp(frenkeLine00)
#' B <- A + frenkeLine00
#' @rdname Arith-methods
#' @aliases Arith,GPR,ANY-method
setMethod(
  f= "Arith",
  signature=c(e1="GPR",e2="ANY"), 
  definition=.GPR.arith
)

#' @name Arith
#' @rdname Arith-methods
#' @aliases Arith,GPR,GPR-method
setMethod(
  f= "Arith",
  signature=c(e1="GPR",e2="GPR"), 
  definition=.GPR.arith
)
#' @name Arith
#' @rdname Arith-methods
#' @aliases Arith,ANY,GPR-method
setMethod(
  f= "Arith",
  signature=c(e1="ANY",e2="GPR"), 
  definition=.GPR.arith
)