[R-pkg-devel] Macros in Rd files.

Duncan Murdoch murdoch.duncan at gmail.com
Fri Nov 10 00:09:05 CET 2017


On 09/11/2017 3:05 PM, Rolf Turner wrote:
> On 09/11/17 23:40, Duncan Murdoch wrote:
>> On 09/11/2017 5:06 AM, Uwe Ligges wrote:
>>> Note the % may be a comment?
>>>
>>
>> Yes, and the body should be written in Rd markup, not R.  Working out
>> the appropriate number of escapes is painful; I recommend trial and error.
>>
>> This worked for me:
>>
>>    \newcommand{\today}{\Sexpr{format(Sys.Date(),"\\\%d/\\\%m/\\\%Y")}}
> 
> Now that is a bit more subtle!  I don't understand what "written in Rd
> markup" really means, and I don't understand the "\Sexpr" construction.
> I'd seen it when looking at the example macros in
> 
>      /usr/local/lib64/R/share/Rd/macros/system.Rd
> 
> but I figured if you know nothing about it, don't mess with it.
> 
> Is there anywhere that I could read up about writing "in Rd markup"?

Not sure this would be helpful, but there's

http://developer.r-project.org/parseRd.pdf

The short summary is this:

Rd files are a mess.  There are several different modes of parsing that 
apply:  at the top level you have Rd code, and in different contexts you 
may have R code (or something close to it), or verbatim code (just 
kidding!  There are ways to signal you want out).  Table 1 in that 
document says what syntax is expected within what macro.  In 
\newcommand, it says it wants "verbatim" input, but really it's going to 
interpret that as Rd input, i.e. LaTeX-like.

Regret asking yet?

Duncan Murdoch

> 
> Anyway, thanks for giving me the recipe, which is what I really need.
> 
> cheers,
> 
> Rolf
>



More information about the R-package-devel mailing list