Question

In conjunction with trying to find a solution for myself in regards to this question, I find myself plunged into trying to write valid Rd markup. What I want is to add a section named Raw Function Code and put the code of the function under it. I've achieved limited success in this regard by writing a script to modify the Rd files to include

\section{Raw Function Code}{\code{
# some piece of R script will eventally provide this part of the text
}}

However, even if I manually properly spaced text into the .Rd file (using either spaces or tabs), the initial white space of each line seems to get stripped away leaving an undesirable looking function. I've noticed that if I provide a starting character before the white space the white space is retained. However, I did not want to provide a starting character because I'd like people to be able to copy and paste directly from the produced PDF.

I have reviewed parseRd and I know there are three types of text LaTeX- like, R-like, and verbatim. I have tried to put my function code in \code and in \verb and neither seemed to yield the desired results. What can I do to hold onto my initial white space?

Was it helpful?

Solution

The \section macro contains LaTeX type of text, but as you want to write code, you could use \synopsis macro, i.e.

\synopsis
# some piece of R script will eventally provide this part of the text
} 

There is one problem with this though; you cannot give name to this section, it is automatically named as another usage section. Same thing could be achieved by using \examples macro, but now the name of the section is Examples, which is probably even more dubious (not to mention that you probably already have Examples section).

OTHER TIPS

It isn't possible without modifying the usage or examples sections of your Rd code. See Hemmo's answer for a usable workaround. It produces text in the verbatim mode which is sub-optimal, but far better than nothing.

(This answer is set community Wiki in case this state of affairs changes. This result is current as of R-2.15.1)

If you want a super hacky way to do it, you can use \Sexpr to make zero width characters and add spaces between them:

#' first line \cr
#'\Sexpr{"\u200B"} \Sexpr{"\u200B"} \Sexpr{"\u200B"} \Sexpr{"\u200B"} indented line

A warning however - your package will build fine, but R CMD CHECK will throw a fit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top