Skip to content

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

17 messages · Uwe Ligges, Duncan Murdoch, François Michonneau +3 more

#
I tried to define a macro to produce today's date (like unto the 
"\today" command in LaTeX):

\newcommand{\today}{format(Sys.date(),"%d/%m/%Y")}

I put this into my *.Rd file just before invoking it.  (Something like
"I don't think I will do any more work today (i.e. \today).")

When I did

     R CMD build ldEst

to my package I got the warning:
Clearly I'm stuffing something up.  Can some kind soul please provide me 
with guidance as to what I *should* be doing?

Ta.

cheers,

Rolf Turner
#
Note the % may be a comment?

Uwe
On 09.11.2017 06:05, Rolf Turner wrote:
#
On 09/11/2017 5:06 AM, Uwe Ligges wrote:
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")}}

Duncan Murdoch
#
On 09/11/17 23:06, Uwe Ligges wrote:
Ah, yes.  Of course!  Duh! (Slaps forehead vigorously!)

Thanks.

cheers,

Rolf
#
On 09/11/17 23:40, Duncan Murdoch wrote:
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"?

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

cheers,

Rolf
#
... Mr. Speaker.
On 09/11/17 23:40, Duncan Murdoch wrote:
Did that, and it worked like a charm.  However when I do the "R CMD 
build" thing, when it comes to the "* building the PDF package manual"
step it says "Hmm ... looks like a package" (no shit, Sherlock!) and 
emits a huge amount of verbose LaTeX diagnostics.

"Normally" one just gets the line "* building the PDF package manual"
and nothing else, and "R CMD build" just carries on cruising.

Evidently defining a macro in the *.Rd file triggers the extra elaboration.

It's no big deal of course, but I just thought I'd ask:

(a) Is there anything to worry about in this respect?

(b) Is there anything different that I should be doing?

(c) Is there anyway of suppressing the (ever-so-slightly annoying)
extra screen output?

I guess that's really three supplementary questions ....

Thanks for any pointers.

cheers,

Rolf
#
On 09/11/2017 3:29 PM, Rolf Turner wrote:
Of course, never ignore diagnostics.  Worry about every line that was 
printed!
Sounds like it...
Oooh, that's such a bad idea.  Don't do that.  Fix the problem that led 
to the output.

Duncan
#
On 09/11/2017 3:05 PM, Rolf Turner wrote:
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
#
On 09/11/2017 3:05 PM, Rolf Turner wrote:
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
#
On 10/11/17 12:00, Duncan Murdoch wrote:
[Rolf Turner wrote:]
Trouble is, I don't (a) know if this really *is* a problem, or (b) if it 
is, any idea of how to work out how to fix it.

I would like to know if it is "an expected phenomenon".  Does it happen 
to other people?  I.e. is there anyone out there who has defined their
own macro in a *.Rd file, and if so, do *they* get a plethora of LaTeX
messages when they do "R CMD build" to the package in question?

I'd love to hear from you! :-)

cheers,

Rolf
#
A github search might be helpful to identify packages that define macros in
their Rd files:
https://github.com/search?utf8=%E2%9C%93&q=user%3Acran+extension%3Ard+newcommand&type=Code
On Thu, Nov 9, 2017 at 6:35 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:

            

  
  
#
On 10/11/17 13:10, Fran?ois Michonneau wrote:
Thanks.  Looking into it.

cheers,

Rolf
#
Hi Rolf,
Another place to look for macros in Rd files would be in the spatstat 
package which I know you are quite familiary with ;-)
However, I think our macros are plain LaTeX without calls to \Sexpr so 
it may behave differently than the case at hand.
Cheers,
Ege
On 11/10/2017 02:00 AM, Rolf Turner wrote:
#
I would add that it is best to think of "Rd markup" as a subset of TeX/LaTeX markup (with some extentions) defined in 
"Writing R Extensions" and Duncan's reference above. 

The "subset" is important - if a feature is not mentioned in these references, it is not available.
 I once inadvertently used a modifier in the tabular environment (maybe something like {l|l|l} which was fine for 'R CMD check', the pdf manual and CRAN but the package failed to install on a system setup for static installation of html documentation.

Georgi Boshnakov

-----Original Message-----
From: R-package-devel [mailto:r-package-devel-bounces at r-project.org] On Behalf Of Duncan Murdoch
Sent: 09 November 2017 23:08
To: Rolf Turner
Cc: r-package-devel at r-project.org
Subject: Re: [R-pkg-devel] Macros in Rd files.
On 09/11/2017 3:05 PM, Rolf Turner wrote:
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
______________________________________________
R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
#
On 10/11/17 09:29, Rolf Turner wrote:

            
Following up a suggestion that I got from Adrian Baddeley I did

    R CMD build --help

(I guess this is a case of RTFM) and I got:
So:  What's triggering the building of the manual is the presence of 
\Sexpr in my macro, and I can suppress this and get rid of all the 
unwanted LaTeX bumff by using the --no-manual flag.

I must say that I don't see why the presence of a \Sexpr (WTF ever that 
is) should trigger the building of the manual.

May I humbly suggest to R Core that this behaviour be modified; perhaps 
there could be a --manual flag asking that the manual be built (whether 
or not there are \Sexpr expressions in the *.Rd files).

cheers,

Rolf
#
It is more subtle than that. 
\Sexpr triggers the creation of "partial Rd database" which becomes part of the built package (the tar.gz file), although what exactly happens may also depend on 'stage' options of the \Sexpr's.
I have never seen  "* building the PDF package manual" from 'R CMD build', see below for a sample console output on Windows from a package which contains Rd macros and vignettes. The messages you show seem to come from 'Rd2pdf'. Is it possible that you have some custom script that builds the manual, as well? Also some environment variable may be the culprit.

Best regards,
Georgi Boshnakov

C:\Users\mcbssgb2\Az\Rdevel\bitbucket\countr_project>R CMD build XXX
* checking for file 'XXX/DESCRIPTION' ... OK
* preparing 'XXX':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to process help pages
* saving partial Rd database
* creating vignettes ... OK
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* looking to see if a 'data/datalist' file should be added
* building 'XXX_3.4.1.tar.gz'



-----Original Message-----
From: R-package-devel [mailto:r-package-devel-bounces at r-project.org] On Behalf Of Rolf Turner
Sent: 10 November 2017 20:01
To: Duncan Murdoch
Cc: r-package-devel at r-project.org
Subject: Re: [R-pkg-devel] Macros in Rd files --- supplementary question.
On 10/11/17 09:29, Rolf Turner wrote:

            
Following up a suggestion that I got from Adrian Baddeley I did

    R CMD build --help

(I guess this is a case of RTFM) and I got:
So:  What's triggering the building of the manual is the presence of \Sexpr in my macro, and I can suppress this and get rid of all the unwanted LaTeX bumff by using the --no-manual flag.

I must say that I don't see why the presence of a \Sexpr (WTF ever that
is) should trigger the building of the manual.

May I humbly suggest to R Core that this behaviour be modified; perhaps there could be a --manual flag asking that the manual be built (whether or not there are \Sexpr expressions in the *.Rd files).

cheers,

Rolf

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
#
On 12/11/17 08:08, Georgi Boshnakov wrote:
But did/do the macros have \Sexpr's in them?
No.  I haven't.

Also some environment variable may be the culprit.

Don't think so.

Anyhow, the message from R CMD build --help very clearly says:
I think that's pretty definitive.

cheers,

Rolf