Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including images in R-package documentation (.Rd) files

I am working to document a visualization function in a package of mine. For this purpose I would like to have an image embedded through the Rd-file 'funcname.Rd' that could explain various parameters utilized in the function, and which would pop up if user goes to read the package manual PDF or writes '?funcname' in R. Something in the lines of:

Manual example

'Writing R extensions'-document doesn't seem to address this issue, and the only references I could find were this blog post and this R-devel discussion. The former has a broken link to a package called 'base64' and the latter only addresses various alternatives like including the images in R package vignettes instead. It would be great if this could be CRAN-compatible.

Any advice on how to approach this issue would be appreciated, thanks!

like image 327
Teemu Daniel Laajala Avatar asked Jan 28 '15 10:01

Teemu Daniel Laajala


People also ask

What is an Rd file in R?

Rd files use a simple markup format that syntactically resembles LaTeX. For detailed documentation on the Rd format please see the article on Writing R Documentation available on CRAN. Rd files are saved in the man directory of an R package. You can create a new Rd file for an existing function, dataset, or other object in two ways:

How to create an your documentation file in R?

Use the File -> New -> R Documentation command in RStudio. This command will allow you to specify the name of an existing function or dataset to use as the basis for the Rd file or alternatively will create a new empty Rd file.

Why use roxygen for package documentation in R?

Using roxygen for package documentation is generally much easier than composing Rd files directly and is highly recommended for new package documentation. Roxygen also plays a prominent roll in the devtools package, a package developed by Hadley Wickham of RStudio that makes it easier to build and document R packages.

What is the best way to document objects in a package?

R provides a standard way of documenting the objects in a package: you write.Rd files in the man/ directory. These files use a custom syntax, loosely based on LaTeX, and are rendered to HTML, plain text and pdf for viewing. Instead of writing these files by hand, we’re going to use roxygen2 which turns specially formatted comments into.Rd files.


1 Answers

Untested, but look at the R source on GitHub, it would appear they add an image to ?par documentation file in the following manner:

 \item{\code{mai}}{A numerical vector of the form \code{c(bottom,
        left, top, right)} which gives the margin size specified in
      inches.\cr
      \if{html}{\figure{mai.png}{options: width="35\%" alt="Figure: mai.png"}}
      \if{latex}{\figure{mai.pdf}{options: width=7cm}}
    }

The figure appears to be saved in /man/figures.

For more details see the Writing R Extensions section on the topic.

like image 137
Roman Luštrik Avatar answered Oct 18 '22 20:10

Roman Luštrik