Title: Minimal R Documentation Generator
Version: 0.3.3
Description: A deterministic, dependency-free documentation generator for R packages. Generates valid Rd files and NAMESPACE from 'roxygen2'-style comments using only base R. Supports a strict subset of tags with no markdown parsing, no inference magic, and explicit-only behavior.
License: GPL-3
URL: https://github.com/cornball-ai/tinyrox
BugReports: https://github.com/cornball-ai/tinyrox/issues
Encoding: UTF-8
Suggests: tinytest
NeedsCompilation: no
Packaged: 2026-04-08 14:32:30 UTC; troy
Author: Troy Hernandez ORCID iD [aut, cre]
Maintainer: Troy Hernandez <troy@cornball.ai>
Repository: CRAN
Date/Publication: 2026-04-15 12:40:02 UTC

Known S3 Generic Functions

Description

List of base R S3 generics for auto-detection when @export is used.

Usage

KNOWN_S3_GENERICS

Format

An object of class character of length 139.


Supported Documentation Tags

Description

Supported Documentation Tags

Usage

SUPPORTED_DOC_TAGS

Format

An object of class character of length 19.


Supported Namespace Tags

Description

Supported Namespace Tags

Usage

SUPPORTED_NS_TAGS

Format

An object of class character of length 6.


All Supported Tags

Description

All Supported Tags

Usage

SUPPORTED_TAGS

Format

An object of class character of length 25.


Check R Code for CRAN Issues

Description

Scans R files for common CRAN policy violations.

Usage

check_code_cran(path = ".")

Arguments

path

Path to package root directory

Value

List with issues found

Examples


# Create a minimal package in tempdir
pkg <- file.path(tempdir(), "mypkg")
dir.create(file.path(pkg, "R"), recursive = TRUE, showWarnings = FALSE)
writeLines("Package: mypkg\nTitle: Test\nVersion: 0.1.0",
    file.path(pkg, "DESCRIPTION"))
writeLines("add <- function(x, y) x + y",
    file.path(pkg, "R", "add.R"))

check_code_cran(pkg)

# Clean up
unlink(pkg, recursive = TRUE)


Check Code Lines for Issues

Description

Check Code Lines for Issues

Usage

check_code_lines(lines, filename)

Arguments

lines

Character vector of code lines

filename

Filename for reporting

Value

List of issues


Full CRAN Compliance Check

Description

Runs all CRAN compliance checks (DESCRIPTION + code).

Usage

check_cran(path = ".")

Arguments

path

Path to package root directory

Value

List with all issues

Examples


# Create a minimal package in tempdir
pkg <- file.path(tempdir(), "mypkg")
dir.create(file.path(pkg, "R"), recursive = TRUE, showWarnings = FALSE)
writeLines("Package: mypkg\nTitle: Test\nVersion: 0.1.0\nDescription: A test package.",
    file.path(pkg, "DESCRIPTION"))
writeLines("add <- function(x, y) x + y",
    file.path(pkg, "R", "add.R"))

check_cran(pkg)

# Clean up
unlink(pkg, recursive = TRUE)


Check DESCRIPTION for CRAN Compliance

Description

Validates Title and Description fields for common CRAN issues: unquoted package names, missing web service links, etc.

Usage

check_description_cran(path = ".", fix = FALSE)

Arguments

path

Path to package root directory

fix

If TRUE, return fixed text. If FALSE, just warn.

Value

List with validation results and optionally fixed text

Examples


# Create a minimal package in tempdir
pkg <- file.path(tempdir(), "mypkg")
dir.create(pkg, recursive = TRUE, showWarnings = FALSE)
writeLines("Package: mypkg\nTitle: Test\nVersion: 0.1.0\nDescription: A test package.",
    file.path(pkg, "DESCRIPTION"))

check_description_cran(pkg)

# Clean up
unlink(pkg, recursive = TRUE)


Check for Missing Examples

Description

Identifies exported functions that lack examples in their documentation.

Usage

check_examples_cran(path = ".")

Arguments

path

Path to package root directory

Value

Character vector of function names missing examples

Examples


# Create a minimal package in tempdir
pkg <- file.path(tempdir(), "mypkg")
dir.create(file.path(pkg, "R"), recursive = TRUE, showWarnings = FALSE)
writeLines("Package: mypkg\nTitle: Test\nVersion: 0.1.0",
    file.path(pkg, "DESCRIPTION"))
writeLines("#' Add numbers\n#' @export\nadd <- function(x, y) x + y",
    file.path(pkg, "R", "add.R"))

check_examples_cran(pkg)

# Clean up
unlink(pkg, recursive = TRUE)


Description

Checks if packages that typically use web services have corresponding URLs in the Description.

Usage

check_webservice_links(description, packages)

Arguments

description

Description text

packages

Package names from dependencies

Value

Named list of packages missing links (name = URL)


Clean Generated Files

Description

Removes all Rd files from man/ directory.

Usage

clean(path = ".", namespace = FALSE)

Arguments

path

Path to package root directory.

namespace

Also remove NAMESPACE? Default FALSE.

Value

No return value, called for side effects.

Examples


# Create a minimal package in tempdir
pkg <- file.path(tempdir(), "mypkg")
dir.create(file.path(pkg, "man"), recursive = TRUE, showWarnings = FALSE)
writeLines("Package: mypkg\nTitle: Test\nVersion: 0.1.0",
    file.path(pkg, "DESCRIPTION"))
writeLines("placeholder", file.path(pkg, "man", "test.Rd"))

clean(pkg)

# Clean up
unlink(pkg, recursive = TRUE)


Detect S3 Method from Function Name

Description

Checks if a function name follows the generic.class pattern where generic is a known S3 generic function.

Usage

detect_s3_method(name, pkg_generics = character())

Arguments

name

Function name to check.

Value

List with generic and class components, or NULL if not an S3 method.


Generate Documentation for an R Package

Description

Main function for tinyrox. Parses R source files for documentation comments and generates Rd files and NAMESPACE.

Usage

document(path = ".", namespace = c("overwrite", "append", "none"),
         cran_check = TRUE)

Arguments

path

Path to package root directory. Default is current directory.

namespace

How to handle NAMESPACE generation. One of

"overwrite"

Fully regenerate NAMESPACE (default)

"append"

Insert between ## tinyrox start/end markers

"none"

Don't modify NAMESPACE

cran_check

Run CRAN compliance checks (DESCRIPTION quoting, web service links, code issues, missing examples). Default TRUE.

Value

Invisibly returns a list with: - rd_files: character vector of generated Rd file paths - namespace: path to NAMESPACE file (or NULL if mode="none")

Examples


# Create a minimal package in tempdir
pkg <- file.path(tempdir(), "mypkg")
dir.create(file.path(pkg, "R"), recursive = TRUE, showWarnings = FALSE)
writeLines("Package: mypkg\nTitle: Test\nVersion: 0.1.0",
    file.path(pkg, "DESCRIPTION"))
writeLines(c(
    "#' Add two numbers",
    "#' @param x A number",
    "#' @param y A number",
    "#' @export",
    "add <- function(x, y) x + y"),
    file.path(pkg, "R", "add.R"))

# Document the package
document(pkg, cran_check = FALSE)

# Clean up
unlink(pkg, recursive = TRUE)


Escape Special Characters for Rd

Description

Escapes special characters for Rd format, but detects and preserves existing Rd markup (like \describe, \item, \code, etc.).

Usage

escape_rd(text)

Arguments

text

Text to escape.

Value

Escaped text.


Escape Regex Special Characters

Description

Escape Regex Special Characters

Usage

escape_regex(x)

Arguments

x

String to escape

Value

Escaped string safe for use in regex


Extract Function Formals from Code

Description

Extract Function Formals from Code

Usage

extract_formals(code)

Arguments

code

Code starting with "function("

Value

List with 'names' (argument names) and 'usage' (formatted for Rd).


Extract Function Name from Definition Line

Description

Extract Function Name from Definition Line

Usage

extract_function_name(line)

Arguments

line

Code line potentially containing function definition

Value

Function name or NULL


Extract Formals from torch nn_module

Description

Extracts the formals from the initialize method of an nn_module definition.

Usage

extract_nn_module_formals(code)

Arguments

code

Code starting with "nn_module(" or "torch::nn_module("

Value

List with 'names' (argument names) and 'usage' (formatted for Rd), or NULL if initialize method not found.


Find Exported Functions Using dontrun in Examples

Description

Parses R file content to find @export tags with \dontrun in @examples.

Usage

find_dontrun_examples(lines)

Arguments

lines

Character vector of file lines

Value

Character vector of function names using dontrun


Find Exported Functions Without Examples

Description

Parses R file content to find @export tags without @examples.

Usage

find_exports_without_examples(lines)

Arguments

lines

Character vector of file lines

Value

Character vector of function names missing examples


Find Example Lines Exceeding 100 Characters

Description

Scans @examples blocks for lines that will be truncated in the PDF manual.

Usage

find_long_example_lines(lines, filename)

Arguments

lines

Character vector of file lines

filename

Filename for reporting

Value

Character vector of warnings (file:line format)


Find S3 generics defined in the package

Description

Scans source files for functions that call UseMethod() to identify package-defined S3 generics.

Usage

find_package_generics(blocks)

Arguments

blocks

Documentation blocks from parse_package().

Value

Character vector of generic function names.


Find Unquoted Names in Text

Description

Finds package/software names that appear without single quotes.

Usage

find_unquoted_names(text, names)

Arguments

text

Text to search

names

Names to look for

Value

Character vector of unquoted names found


Fix DESCRIPTION File

Description

Automatically fixes common CRAN issues in DESCRIPTION.

Usage

fix_description_cran(path = ".", backup = TRUE)

Arguments

path

Path to package root directory

backup

Create backup file? Default TRUE.

Value

Invisibly returns TRUE if changes were made

Examples


# Create a minimal package in tempdir
pkg <- file.path(tempdir(), "mypkg")
dir.create(pkg, recursive = TRUE, showWarnings = FALSE)
writeLines("Package: mypkg\nTitle: Test\nVersion: 0.1.0\nDescription: A test package.",
    file.path(pkg, "DESCRIPTION"))

fix_description_cran(pkg, backup = FALSE)

# Clean up
unlink(pkg, recursive = TRUE)


Format Object Info for Data Documentation

Description

Generates the format description string for a data object. Tries to load the package namespace to inspect the object.

Usage

format_object_info(name, pkg_path)

Arguments

name

Object name.

pkg_path

Package root path.

Value

Format string or NULL if object cannot be inspected.


Format Usage Line

Description

Formats the function usage, wrapping to multiple lines if needed. Follows roxygen2 style: each argument on its own line if total > 80 chars. S3 methods use the \method syntax.

Usage

format_usage(name, args, pkg_generics = character())

Arguments

name

Function name.

args

Character vector of arguments with defaults.

Value

Formatted usage string.


Generate All Rd Files for a Package

Description

Generate All Rd Files for a Package

Usage

generate_all_rd(blocks, path = ".")

Arguments

blocks

List of documentation blocks from parse_package().

path

Package root path.

Value

Character vector of generated file paths.


Generate Rd File Content for Data Objects

Description

Generate Rd File Content for Data Objects

Usage

generate_data_rd(tags, source_file = NULL, format_string = NULL)

Arguments

tags

Parsed tags from parse_tags().

source_file

Source file path (for header comment).

format_string

Format description (e.g., "An object of class list of length 3").

Value

Character string of Rd content.


Generate NAMESPACE Content

Description

Generate NAMESPACE Content

Usage

generate_namespace(blocks)

Arguments

blocks

List of documentation blocks from parse_package().

Value

Character string of NAMESPACE content.


Generate Package Documentation Rd

Description

Generates Rd content for package documentation ("_PACKAGE" directive).

Usage

generate_package_rd(tags, pkg_name, source_file)

Arguments

tags

Parsed tags from the documentation block.

pkg_name

Package name.

source_file

Source file path.

Value

Character string of Rd content.


Generate Rd File Content

Description

Generate Rd File Content

Usage

generate_rd(tags, formals = NULL, source_file = NULL, pkg_generics = character())

Arguments

tags

Parsed tags from parse_tags().

formals

Character vector of formal argument names (for functions).

source_file

Source file path (for header comment).

Value

Character string of Rd content.


Generate Rd Content for Grouped Blocks (Multiple @rdname Entries)

Description

Merges multiple documentation blocks that share an @rdname topic into a single .Rd file. The primary block (whose name matches the topic) provides title/description; all blocks contribute usage/params.

Usage

generate_rd_grouped(topic, entries, all_tags, pkg_generics = character())

Arguments

topic

Topic name (the @rdname value).

entries

List of list(tags, block) pairs sharing this topic.

all_tags

All parsed tags (for @inheritParams resolution).

Value

Character string of merged Rd content.


Extract Package Names from Dependencies

Description

Parses Imports, Suggests, Depends, and Enhances fields.

Usage

get_dependency_packages(desc)

Arguments

desc

DESCRIPTION matrix from read.dcf()

Value

Character vector of package names


Get Maintainer Info from DESCRIPTION

Description

Reads Authors@R from DESCRIPTION and formats maintainer for Rd.

Usage

get_maintainer_from_desc(path)

Arguments

path

Package root path.

Value

Formatted author string or NULL.


Get Package Name from DESCRIPTION

Description

Get Package Name from DESCRIPTION

Usage

get_package_name(path)

Arguments

path

Package root path.

Value

Package name.


Parse R Files for Documentation Blocks

Description

Extracts documentation comment blocks and their associated objects from R source files.

Usage

parse_file(file)

Arguments

file

Path to an R source file.

Value

A list of documentation blocks, each with components: - lines: character vector of comment lines (without #') - object: name of the documented object - type: "function", "data", or "other" - formals: for functions, the formal arguments


Parse Formals Text

Description

Parse Formals Text

Usage

parse_formals_text(text)

Arguments

text

Text containing function arguments.

Value

List with 'names' (argument names) and 'usage' (formatted for Rd).


Parse Object Definition

Description

Identifies the object being defined from code text (may be multi-line).

Usage

parse_object_definition(text, file, line_num)

Arguments

text

The code text (may span multiple lines).

file

The source file (for error messages).

line_num

The line number (for error messages).

Value

A list with name, type, and formals, or NULL if not a definition.


Parse All R Files in a Package

Description

Parse All R Files in a Package

Usage

parse_package(path = ".")

Arguments

path

Path to package root.

Value

List of all documentation blocks from all R files.


Parse Tags from Documentation Lines

Description

Parse Tags from Documentation Lines

Usage

parse_tags(lines, object_name, file = NULL, line_num = NULL)

Arguments

lines

Character vector of documentation lines (without #').

object_name

Name of the documented object.

file

Source file (for error messages).

line_num

Starting line number (for error messages).

Value

A list with parsed tag values.

Examples

lines <- c("Title Here", "", "Description text.", "", "@param x A number.",
  "@return The number.", "@export")
tags <- parse_tags(lines, "my_function")
tags$title
tags$params


Quote Names in Text

Description

Wraps unquoted package/software names in single quotes.

Usage

quote_names_in_text(text, names)

Arguments

text

Text to modify

names

Names to quote

Value

Modified text with names quoted


Resolve Parameters from External Package Rd Files

Description

Reads an installed package's Rd file to extract parameter documentation for use with '@inheritParams pkg::function'.

Usage

resolve_external_params(source_name)

Arguments

source_name

Character string like "base::cat" or "stats::lm".

Value

Named list of parameter descriptions, or empty list on failure.


Resolve @inheritParams Tags

Description

Copies parameter documentation from source functions to the current function. Only inherits params that are: (1) in the current function's formals, and (2) not already documented in the current function.

Usage

resolve_inherit_params(tags, all_tags, formals)

Arguments

tags

Current function's parsed tags.

all_tags

Named list of all parsed tags (name -> tags).

formals

Current function's formals (list with names and usage).

Value

Updated tags with inherited params merged in.


Save a Parsed Tag Value

Description

Save a Parsed Tag Value

Usage

save_tag(result, tag, arg, accumulator, file, line_num)

Arguments

result

Current result list to update.

tag

Tag name (e.g., "param", "return").

arg

First-line argument after the tag.

accumulator

Continuation lines for the tag.

file

Source file path (for error messages).

line_num

Line number (for error messages).


Wrap Text to Width

Description

Wraps text to specified width, preserving words.

Usage

wrap_text(text, width = 72)

Arguments

text

Text to wrap.

width

Maximum line width.

Value

Wrapped text with newlines.


Write NAMESPACE File

Description

Write NAMESPACE File

Usage

write_namespace(content, path = ".", mode = "overwrite")

Arguments

content

NAMESPACE content string.

path

Package root path.

mode

Either "overwrite" or "append".


Write Rd File

Description

Write Rd File

Usage

write_rd(content, name, path = ".")

Arguments

content

Rd content string.

name

Topic name.

path

Package root path.