by Andrie de Vries
Have you noticed that most R help does not contain any images? Historically, this was for a good reason: most programming language help assumes that you use the system on a text-only system, e.g. a headless linux server. If your system has no graphical capabilities, but the help contains images, then the help itself can become confusing.
That said, most R users use their help on a system with full graphical capabilities. Thus the R core team updated R itself in version 2.12 to have the ability to include images in your help.
The question is how do you go about creating help files that contain images?
My search engine skills only uncovered two references:
- A blog post by Romain Francois: “embed images in Rd documents“.
- An answer to a question on StackOverflow: “Including images in R-package documentation (.Rd) files“. This was answered by Roman Lustrik.
Both approaches require you to use a tag in your .Rd file:
- Use the sexpr tag:
- Romain’s suggestion is really powerful, since it uses a mechanism to dynamically render R code directly in your Rd file. I didn’t know this, but the R Extensions manual describes how to use the tag sexpr to render R code dynamically. In his blog post, Romain gives an example of doing this.
- Use the figure tag:
- The answer at StackOverflow points to the figure tag. This allows you to post a png image into HTML help, or a pdf image into PDF help.
Putting this into action
For one of the projects I’m working on, the AzureML package, I opted for the second option. The AzureML package (source code on github) allows you to interact with the AzureML Machine Learning Studio, directly from R.
I wanted to include some diagrams in the help pages to …read more
Source:: http://revolutionanalytics.com