knit_roff: Knit an R troff document

View source: R/knitroff.R

knit_roffR Documentation

Knit an R troff document

Description

Runs the R code of a troff document and writes plain troff, ready for GNU groff with the -ms macros. Code chunks sit between .SS and .SE, the way eqn blocks sit between .EQ and .EN; chunk options follow .SS, as in .SS scatter, fig.cap="Income", echo=FALSE. Inline results are written `r expr`, and .SR name expr defines the troff string \*[name] with the value of expr.

Usage

knit_roff(input, output = NULL, format = c("pdf", "ps", "utf8"), highlight = TRUE,
          quiet = TRUE)

Arguments

input

Path of the document, usually ‘.Rms’.

output

Path of the troff file. By default input with extension ‘.ms’.

format

What the troff is for: "pdf" and "ps" include figures with .PDFPIC and .PSPIC; "utf8", the terminal draft, leaves a box to paste each figure into and shows each equation as its eqn source.

highlight

Set R keywords in bold and comments in italic, in the constant-width bold and italic fonts, as printed listings did. FALSE gives the plain listing of 1981. A chunk can choose for itself with .SS highlight=FALSE or TRUE.

quiet

Passed to knit.

Details

Each chunk becomes one listing in a constant-width font: the code with > and + prompts, its output under it, kept together on a page. Figures are written to a directory named after the document. knitr's patterns, hooks and options are restored afterwards. No groff is needed to knit.

Value

The path of the troff file, invisibly.

See Also

render_roff to typeset the result, roff_table.

Examples

doc <- file.path(tempdir(), "mean.Rms")
writeLines(c(".PP", "The mean of 1 to 10 is `r mean(1:10)`.",
             ".SS", "x <- 1:10", "summary(x)", ".SE"), doc)
cat(readLines(knit_roff(doc, format = "utf8")), sep = "\n")

knitroff documentation built on Oct. 16, 2026, 5:09 p.m.