Learn R Programming

Rd

The goal of Rd is to extend the base utilities in the tools and utils package to facilitate creation, checking and manipulation of R documentation (Rd) objects in code.

Installation

You can install the released version of Rd from CRAN with:

install.packages("Rd")

Examples

This is a basic example for constructing an Rd document from scratch:

## Recreating the first few lines of the `example` help file. 
R <- Rd_tag("\\R")
Rd( Rd_name('example'), '\n'
  , Rd_alias('example'), '\n'
  , Rd_title("Run an Examples Section from the Online Help"), '\n'
  , Rd_description( "Run all ", R, " code from the "
                  , Rd_tag("\\bold", "Examples"), " part of \n"    
                  , R, "'s online help topic ", Rd_code("topic")
                  , " with possible exceptions \n"
                  , Rd_code("dontrun"), ", "
                  , Rd_code("dontshow"), ", and "
                  , Rd_code("donttest"), ",\n see "
                  , Rd_tag("\\sQuote", "Details"), " below."
                  )
  )
#> \name{example}
#> \alias{example}
#> \title{Run an Examples Section from the Online Help}
#> \description{
#> Run all \R code from the \bold{Examples} part of 
#> \R's online help topic \code{topic} with possible exceptions 
#> \code{dontrun}, \code{dontshow}, and \code{donttest},
#>  see \sQuote{Details} below.
#> }

Note that the line breaks are unnecessary for functionality, they are included

Details and Internals

Differences from core R

Rd Objects are composed of character strings and lists of character strings or nested lists ultimately ending in character strings. The primary tool for reading in Rd object is the tools::parse_Rd() function. This will return a list with the base object being an Rd object but none of the elements contained are classed. The Rd package extends this with providing more methods and functions for handling these. In Rd all objects are S3 classed, including tags, text, code, and comments.

Classes

Rd

This exists in the base R and is what is returned by Rd_text('test'). The Rd package adds S3 Methods [[, [, c, and format. Rd objects must be lists to be valid.

Rd_string

The Rd text is a character string, a length one non-empty character vector. It contains several different categories of text which is specified in the Rd_tag attribute:

  • "TEXT" - The generic text type
  • "RCODE" - Tagged as R code, but note that this should be wrapped by an appropriate Rd_tag object described below.
  • "VERB" - Symbols such as function names.
  • "COMMENT" - Comments in Rd, each should lead with the comment character '%'.
  • "UNKNOWN" - If it cannot be categorized.

It should be noted that the different types of Rd_string is for contextual identification, but for printing and formatting all are returned verbatim.

Rd_tag

The Rd_tag objects are converted to the latex like \tag commands when formatted for printing or writing files. The tag to be used is stored in the Rd_tag attribute.

Copy Link

Version

Install

install.packages('Rd')

Monthly Downloads

20

Version

0.2.0

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Andrew Redd

Last Published

May 23rd, 2019

Functions in Rd (0.2.0)

Rd_split

Split a rd object into relevant lines.
toRd

Convert an object to Rd
Rd_clean_indent

Check and clean an indent string
is_Rd_newline

Check if an element is a newline
Rd_canonize

Rd Canonical Form
pieces

Rd Pieces
Rd_string_creation

Rd String Construction
Rd_tag

Create an Rd tag container
Rd_compact

Compact a list into an Rd vector
shortcuts

Convenience Construction Shortcuts.
Rd

Construct an Rd container
testing-Rd

Testing Rd types These provide methods for testing if an object is valid.
aliases

Internal Utilities These utilities are used internally and not exported. They are however documented for completeness
Rd_c

Combine Rd elements
Rd-extraction

Extract elements from Rd containers These functions can be used to extract or subset elements of Rd lists, either bare Rd containers or Rd_tag objects. The [[ operator performs classification of output. Rd_get_element acts as [[ but will also accept tags to search for. The [ operator wraps Rd_subset, respectively.
Rd_indent

Indent Rd
Rd_lines

Combine with line breaks