Here’s a brief example of a function add_numbers() with its roxygen documentation:
#' Add two numbers together.#'#' This function takes two numeric inputs and returns their sum.#'#' @param x A numeric value, the first number.#' @param y A numeric value, the second number.#' @return The sum of `x` and `y`.#' @examples#' add_numbers(5, 3)#' add_numbers(10, -2)add_numbers <-function(x, y) { x + y}
Documentation Files: .Rd
% Generated by roxygen2: do not edit by hand% Please edit documentation in R/add_numbers.R\name{add_numbers}\alias{add_numbers}\title{Add two numbers together.}\usage{add_numbers(x, y)}\arguments{\item{x}{A numeric value, the first number.\describe{\item{Default value}{none}}}\item{y}{A numeric value, the second number.\describe{\item{Default value}{none}}}}\value{The sum of \code{x} and \code{y}.}\description{This function takes two numeric inputs and returns their sum.}\examples{add_numbers(5, 3)add_numbers(10, -2)}
Don’t touch!
I do not recommend editing these by hand - ever - unless you want pain!
{admiraldev} houses the functions in roclet_rdx.R to allow for extensions
Extending the roclet
#' A Demo Function#'#' This function is used to demonstrate the custom tags of the `rdx_roclet()`.#'#' @param x An argument#' @param number A number#' @permitted A number#' @param letter A letter#' @permitted [char_scalar]#' @default The first letter of the alphabet#' @keywords internal#' @examplesx#' @info This is the introduction.#' @caption A simple example#' @info This is a simple example showing the default behaviour.#' @code demo_fun(1)#' @caption An example with a different letter#' @info This example shows that the `letter` argument does not#' affect the output.#' @code demo_fun(1, letter = "b")demo_fun <-function(x, number =1, letter ="a") 42
Eck! A small subset of the .Rd
% Generated by roxygen2: do not edit by hand% Please edit documentation in R/demo_fun.R\name{demo_fun}\alias{demo_fun}\title{A Demo Function}\usage{demo_fun(x, number = 1, letter = "a")}...\keyword{internal}\section{Examples}{This is the introduction.\subsection{A simple example}{This is a simple example showing the default behaviour.\if{html}{\out{<div class="sourceCode r">}}\preformatted{demo_fun(1)#> [1] 42}\if{html}{\out{</div>}}}\subsection{An example with a different letter}{This example shows that the \code{letter} argument does not affect the output.\if{html}{\out{<div class="sourceCode r">}}\preformatted{demo_fun(1, letter = "b")#> [1] 42}\if{html}{\out{</div>}}}}
Technical Takeaway
New Tags on the Block:
@examplesx
@caption
@info
@code
Get into the purpose, how it works and the processing (briefly!!)
@examplesx - The Examples Section
Purpose: Marks the start of the entire examples section.
How it Works: Triggers transform_examplesx() to begin processing the custom tags that follow.
Processing: Groups @caption, @info, and @code tags into structured examples; cleans up special characters to avoid formatting issues in the final docs.
@caption - Example Title
Purpose: Sets the title for an individual example.
How it Works: Each @caption starts a new example block; the text that follows becomes the title.
Processing: Formatted as a \subsection{} inside the main \section{Examples}{} in the final .Rd file.
@info - Example Description
Purpose: Adds a short description or context for a specific example.
How it Works: Placed after @caption and before @code to explain what the example demonstrates.
Processing: The descriptive text is added to the example block and included in the final documentation.
@code - Executable Example Code
Purpose: Contains the actual R code that gets run and displayed in the docs.
How it Works: The code following @code is executed; use [expected_cnds = "warning"] to flag expected warnings or errors.
Processing: Code runs in a controlled environment via execute_example(); unexpected conditions cause an R CMD check failure, ensuring examples actually work.
Conclusion
The admiral R package faced challenges with unwieldy function documentation due to complex and numerous examples.
To address this, admiral extended roxygen2’s roclets by introducing custom Roxygen tags: @examplesx, @caption, @info, and @code.
These custom tags enable a structured, user-friendly presentation of examples, providing scaffolding for complex function usage.
This innovation significantly improved the overall user experience and the quality of admiral’s function documentation.
In this age of AI - high quality documentation will be key to a software products long-term usefulness.
Question
What is the name of the documentation package that could be extended to address admiral’s needs?