| name | roxygen2-pkgdown |
| description | R package documentation with roxygen2 and pkgdown, including reference topics, articles, and site configuration. |
roxygen2 and pkgdown
Overview
Complete reference for roxygen2 documentation syntax and pkgdown site configuration. Covers all roxygen2 tags, cross-referencing, and advanced pkgdown customization.
roxygen2 Fundamentals
Basic Tags
Parameter Documentation
Return Value Documentation
Examples
Cross-Referencing
Linking to Functions
Linking to Topics
Advanced roxygen2 Tags
Inheritance
Function Families
Multiple Functions Per File
function_a <- function(x) {}
function_b <- function(x) {}
Conditional Exports
S3 Methods
print.myclass <- function(x, ...) {}
print.myclass <- function(x, ...) {}
S4 Classes and Methods
setClass("MyClass", slots = c(x = "numeric", y = "character"))
setMethod("mymethod", "MyClass", function(object) {})
Imports
Markdown in roxygen2
Enable Markdown
Roxygen: list(markdown = TRUE)
Markdown Syntax
pkgdown Configuration
Basic _pkgdown.yml
url: https://user.github.io/pkg/
template:
bootstrap: 5
bootswatch: flatly
navbar:
structure:
left: [intro, reference, articles, tutorials, news]
right: [search, github]
components:
github:
icon: fab fa-github
href: https://github.com/user/pkg
reference:
- title: Main Functions
desc: Core functionality
contents:
- main_function
- helper_function
- title: Utilities
contents:
- starts_with("util_")
- title: internal
contents:
- internal_function
articles:
- title: Getting Started
navbar: ~
contents:
- pkgname
- title: Advanced Topics
contents:
- advanced-usage
- customization
news:
releases:
- text: "Version 1.0.0"
href: https://github.com/user/pkg/releases/tag/v1.0.0
Reference Organization
reference:
- title: Data Import
desc: Functions for importing data
contents:
- read_data
- read_csv_data
- matches("^read_")
- title: Data Transformation
contents:
- transform_data
- starts_with("transform_")
- title: Analysis
contents:
- has_concept("analysis")
- title: Visualization
contents:
- has_keyword("plot")
- subtitle: Core Plots
contents:
- plot_main
- subtitle: Diagnostic Plots
contents:
- plot_diagnostics
Custom Styling
template:
bootstrap: 5
bootswatch: flatly
bslib:
primary: "#0054AD"
border-radius: 0.5rem
btn-border-radius: 0.25rem
includes:
in_header: |
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js"></script>
Home Page Customization
home:
title: Package Name
description: One-line description
links:
- text: Learn more
href: https://example.com
sidebar:
structure: [links, license, community, citation, authors, dev]
Articles Configuration
articles:
- title: Tutorials
navbar: Tutorials
contents:
- articles/getting-started
- articles/basic-usage
- title: Advanced
navbar: Advanced
contents:
- articles/advanced-topics
- title: Internal
contents:
- articles/internal-docs
Building pkgdown Site
Build Commands
pkgdown::build_site()
pkgdown::build_home()
pkgdown::build_reference()
pkgdown::build_articles()
pkgdown::build_news()
pkgdown::preview_site()
pkgdown::check_pkgdown()
GitHub Actions Deployment
on:
push:
branches: [main, master]
release:
types: [published]
workflow_dispatch:
name: pkgdown
jobs:
pkgdown:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website
- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}
- name: Deploy to GitHub pages
uses: JamesIves/github-pages-deploy-action@v4
with:
clean: false
branch: gh-pages
folder: docs
Workflow
devtools::document()
devtools::check()
pkgdown::build_site()
pkgdown::build_reference_index()
pkgdown::build_article("vignette-name")
Common Patterns
Reexporting Functions
magrittr::`%>%`
rlang::.data
Deprecated Functions
old_function <- function(...) {
lifecycle::deprecate_warn("1.0.0", "old_function()", "new_function()")
new_function(...)
}
Internal Functions
internal_helper <- function(x) {}