| Title: | Minimal R Documentation Generator |
|---|---|
| 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. |
| Authors: | Troy Hernandez [aut, cre] (ORCID: <https://orcid.org/0009-0005-4248-604X>) |
| Maintainer: | Troy Hernandez <[email protected]> |
| License: | GPL-3 |
| Version: | 0.3.3 |
| Built: | 2026-05-24 06:04:55 UTC |
| Source: | https://github.com/cornball-ai/tinyrox |
Scans R files for common CRAN policy violations.
check_code_cran(path = ".")check_code_cran(path = ".")
path |
Path to package root directory |
List with issues found
# 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)# 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
check_code_lines(lines, filename)check_code_lines(lines, filename)
lines |
Character vector of code lines |
filename |
Filename for reporting |
List of issues
Runs all CRAN compliance checks (DESCRIPTION + code).
check_cran(path = ".")check_cran(path = ".")
path |
Path to package root directory |
List with all issues
# 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)# 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)
Validates Title and Description fields for common CRAN issues: unquoted package names, missing web service links, etc.
check_description_cran(path = ".", fix = FALSE)check_description_cran(path = ".", fix = FALSE)
path |
Path to package root directory |
fix |
If TRUE, return fixed text. If FALSE, just warn. |
List with validation results and optionally fixed text
# 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)# 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)
Identifies exported functions that lack examples in their documentation.
check_examples_cran(path = ".")check_examples_cran(path = ".")
path |
Path to package root directory |
Character vector of function names missing 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)# 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)
Checks if packages that typically use web services have corresponding URLs in the Description.
check_webservice_links(description, packages)check_webservice_links(description, packages)
description |
Description text |
packages |
Package names from dependencies |
Named list of packages missing links (name = URL)
Removes all Rd files from man/ directory.
clean(path = ".", namespace = FALSE)clean(path = ".", namespace = FALSE)
path |
Path to package root directory. |
namespace |
Also remove NAMESPACE? Default FALSE. |
No return value, called for side effects.
# 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)# 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)
Main function for tinyrox. Parses R source files for documentation comments and generates Rd files and NAMESPACE.
document(path = ".", namespace = c("overwrite", "append", "none"), cran_check = TRUE)document(path = ".", namespace = c("overwrite", "append", "none"), cran_check = TRUE)
path |
Path to package root directory. Default is current directory. |
namespace |
How to handle NAMESPACE generation. One of
|
cran_check |
Run CRAN compliance checks (DESCRIPTION quoting, web service links, code issues, missing examples). Default TRUE. |
Invisibly returns a list with: - rd_files: character vector of generated Rd file paths - namespace: path to NAMESPACE file (or NULL if mode="none")
# 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)# 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 Regex Special Characters
escape_regex(x)escape_regex(x)
x |
String to escape |
Escaped string safe for use in regex
Extract Function Name from Definition Line
extract_function_name(line)extract_function_name(line)
line |
Code line potentially containing function definition |
Function name or NULL
Parses R file content to find @export tags with \dontrun in @examples.
find_dontrun_examples(lines)find_dontrun_examples(lines)
lines |
Character vector of file lines |
Character vector of function names using dontrun
Parses R file content to find @export tags without @examples.
find_exports_without_examples(lines)find_exports_without_examples(lines)
lines |
Character vector of file lines |
Character vector of function names missing examples
Scans @examples blocks for lines that will be truncated in the PDF manual.
find_long_example_lines(lines, filename)find_long_example_lines(lines, filename)
lines |
Character vector of file lines |
filename |
Filename for reporting |
Character vector of warnings (file:line format)
Finds package/software names that appear without single quotes.
find_unquoted_names(text, names)find_unquoted_names(text, names)
text |
Text to search |
names |
Names to look for |
Character vector of unquoted names found
Automatically fixes common CRAN issues in DESCRIPTION.
fix_description_cran(path = ".", backup = TRUE)fix_description_cran(path = ".", backup = TRUE)
path |
Path to package root directory |
backup |
Create backup file? Default TRUE. |
Invisibly returns TRUE if changes were made
# 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)# 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)
Parses Imports, Suggests, Depends, and Enhances fields.
get_dependency_packages(desc)get_dependency_packages(desc)
desc |
DESCRIPTION matrix from read.dcf() |
Character vector of package names
Parse Tags from Documentation Lines
parse_tags(lines, object_name, file = NULL, line_num = NULL)parse_tags(lines, object_name, file = NULL, line_num = NULL)
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). |
A list with parsed tag values.
lines <- c("Title Here", "", "Description text.", "", "@param x A number.", "@return The number.", "@export") tags <- parse_tags(lines, "my_function") tags$title tags$paramslines <- c("Title Here", "", "Description text.", "", "@param x A number.", "@return The number.", "@export") tags <- parse_tags(lines, "my_function") tags$title tags$params
Wraps unquoted package/software names in single quotes.
quote_names_in_text(text, names)quote_names_in_text(text, names)
text |
Text to modify |
names |
Names to quote |
Modified text with names quoted