Skip to content

roxygen2

Basic documentation

Action Code Details
Title
@title Title here
Description
@description Description here
Parameter
@param data The dataset
Dot parameters
@param ... Additional arguments
Return
@return Return value description here
Class slot
@slot slotName Description here
Details
@details Details here
Note
@note Notes here
Data format
@format Format description here

Text formatting

Action Code Details
Enable markdown
@md
Emphasis
_wow_
Bold
*wow*
In-line equation
\eqn{a + b}
Display equation
\deqn{a + b}
Code
`mu <- mean(data)`
Code
\code{mu <- mean(data)}
Code block

mu <- mean(data)

Monospace font (looks like code)
\preformatted{
    text
}
Package name
\pkg{stats}
Unordered list
\itemize{
    \item Option A
    \item Option B
}
Ordered list
\enumerate{
    \item First item
    \item Second item
}
Named list
\describe{
    \item{Opt A}{Describe option A}<
    \item{Opt B}{Describe option B}
}
Table
?
Use markdown?
Sections
@details First part
@details Second part (will be a new section)
Arbitrary sections
@section Title:
Text here
Subsections
@details
## This is a subsection
With text
#### Subsubsection here
With text
Action Code Details
Website
<https://r-project.org>
With different text
[text](link)
To internal topic defined by @name name
[name]
To external package
[stats][stats-package]
To external package function
[stats::predict]
To internal or global function
[predict()]
To package function
[stats::predict()]
To function with different text
[fancyName()][stats::predict()]
To class
[Time]
To external class
[stats::Time]
To S4 class
\linkS4class{lcModel}
With special characters
\code{\link[magrittr]{\%>\%}}
See-also
@seealso [mean] [stats::median]
See-also vignette
@seealso browseVignettes('roxygen2')
Family
@family sharedNames
Specify source
@source This dataset was generated using [generateData]
References
@references
\insertRef{benaglia2009mixtools}{latrend}
E-mail
\email{example@@example.com}

Examples

Documenting code examples

Action Code Details
Examples
@examples
1 + 1
mean(1:9)
Examples that should not be run
@examples
1 + 1
\dontrun{
    stop('oops')
}
Examples that should not be tested
@examples
\donttest{
    stop('oops')
}
Examples for interactive usage only
@examples
if interactive()
    browseURL("https://roxygen2.r-lib.org")

Dynamic content

Action Code Details
In-line code evaluation
`r getRversion()`
Evaluated during every roxygenize call
Code block evaluation
```{r}
1 + 1
</td>
<td markdown="1">Code blocks cannot refer to each other</td>
</tr>
<tr markdown="1">
<td markdown="1">
Generate figure
</td>
<td>
```R
```{r iris-pairs-plot}
pairs(iris[1:4])[unclass(iris$Species)])
</td>
<td markdown="1"></td>
</tr>
<tr markdown="1">
<td markdown="1">
Dynamic documentation
</td>
<td>
```R
![image](https://example.com)

Generating documentation

Action Code Details
Generate docs
roxygen2::roxygenise()
Ctrl+Shift+D
Clean files, then generate docs
roxygen2::roxygenise(clean = TRUE)

Topics

Action Code Details
Don't generate topic
@noRd
Create stand-alone topic
@name docname
@title Topic title
NULL
Package topic
@details
Package documentation here.
@keywords internal
"_PACKAGE"
Topic name
@name simpleName
Topic file name
@rdname simpleName
Specify doc inclusion order
@order 1
Then @order 2 for the second doc
Define alias
@aliases shortName
Define alias for S4 method
@aliases predictForCluster,lcModel-method
Inherit doc
@inherit docName
Inherit doc components
@inherit docName details return
Inherit section
@inheritSection docName Section title
Inherit param descriptions from another internal function
@inheritParams internalFun
Inherit param descriptions from an external function
@inheritParams stats::predict
Inherit dot parameters
@inheritDotParams
Hide documentation
@keywords internal

Namespace generation

Action Code Details
Import package
@import stats
Import packages
@import stats splines
Import function(s) from package
@importFrom stats predict fitted
Import S3 generic
@importFrom pkg generic
Import S4 classes from package
@importClassesFrom stats Time
Import S4 methods from package
@importMethodsFrom stats time time2
Collate / ensure other R files are loaded first
@include first.R second.R
Export function
@export
Export class and methods
@export
setClass(…)
Export class
@exportClass lcModel
Export class method
@exportMethod evaluate