Skip to content

Possible bug in the Rd parser?

7 messages · Duncan Murdoch, Mathieu Ribatet, Brian Ripley

#
Dear list,

I got an automatic email complaining than some of my packages didn't
pass 'R CMD check' for R-2.10.0 alpha anymore. Both of them make use of
the "cases" LaTeX environment.

Inspecting the log outputs I got:

        LaTeX errors when creating PDF version.
        This typically indicates Rd problems.
        LaTeX errors found:
        ! Misplaced alignment tab character &.

I noticed that the Rd parser changed quite recently and that '#', '_'
and '&' must not be escaped according to "Writing R extensions".
However, the problematic .Rd portion seems (to me) OK

        \deqn{\theta(h) =
            \begin{cases}
            u_\beta \left(\mu +  \frac{\nu(h)}{\Gamma(1 - \xi)}
        \right),&\xi \neq 0\\
            \exp\left(\frac{\nu(h)}{\sigma}\right),&\xi = 0
            \end{cases}
          }{u_beta (mu + nu(h) / Gamma(1 - \xi)), if \xi < 1,
            exp(nu(h)/sigma), otherwise}

Removing the alignment tab character '&' solves the issue but doesn't
produce the expected LaTeX output. Do I miss something with the new Rd
parser requirements?

I'm not 100% sure but it also seems like that "\\' symbol isn't
interpreted as a break line - in the "cases" environment at least. This
might be one reason why the alignment tab '&' is misplaced.

Best,
Mathieu
#
On 10/10/2009 8:07 AM, Mathieu Ribatet wrote:
I think the new parser is working properly, but there is something wrong 
with your LaTeX.  When I paste that block into a test file and run it 
through the 2.9 parser, the \\ gets converted to \bsl{}, and garbage 
results.  The new parser faithfully reproduces what you wrote, but for 
some reason it's not legal LaTeX.

I suspect the problem is that the text is generated within a \deqn{} 
macro, which is defined in Rd.sty.  Something you're doing is not 
allowed in that context.

It's helpful to run

Rcmd Rd2dvi --no-clean test.Rd

to be able to examine the LaTeX produced by R (which will be saved in a 
temporary directory; the --no-clean tells R not to delete it at the end).

I don't know LaTeX well enough to tell you the best workaround for this, 
but one option is to used the recently added \if or \ifelse and \out 
macros instead of \deqn.  Of course, that will make your Rd file 
unusable in earlier versions, so it's not necessarily the best idea.

Duncan Murdoch
#
On 10/10/2009 8:07 AM, Mathieu Ribatet wrote:
One more followup:  the problem appears to be in the "cases" 
environment.  If I rewrite that block using "array" instead, things are 
fine:

         \deqn{\theta(h) =
             \left\{\begin{array}{ll}
             u_\beta \left(\mu +  \frac{\nu(h)}{\Gamma(1 - \xi)}
         \right),&\xi \neq 0\\
             \exp\left(\frac{\nu(h)}{\sigma}\right),&\xi = 0
             \end{array}\right.
           }{u_beta (mu + nu(h) / Gamma(1 - \xi)), if \xi < 1,
             exp(nu(h)/sigma), otherwise}

This makes me think it's a bug in the LaTeX package that provides 
"cases", or a conflict with our Rd.sty file, but I don't know which.

Duncan Murdoch
#
On 10/10/2009 2:25 PM, Duncan Murdoch wrote:
And the final answer:  the "cases" environment is in the amsmath 
package, which is not used by R.  You need to use regular LaTeX, not 
fancy stuff like that.  (There's a \cases macro in LaTex, which doesn't 
know what to do with alignment tabs:  that's why you got the error you did.)

Duncan Murdoch
#
Thanks Duncan for all these answers. Indeed I should have checked that
the "cases" environment was provided by Rd.sty. Mea culpa.

The good point is that before 2.10.0 alpha "R CMD check" finished
without any error but the output was wrong - because of the cases
environment as you said. Now it fails and this is a good point as I,
maybe others??, usually don't have a look at "mypkg-manual.pdf" but only
at the html version of it.

Cheers,
Mathieu  

Le samedi 10 octobre 2009 ? 20:40 +0200, Duncan Murdoch a ?crit :
#
Mathieu Ribatet wrote:
Yes, the new system is much better at detecting errors than the old 
one.  It does require some changes to things that worked before, but 
mainly it detects things that weren't working before, but were 
undetected as errors.

Duncan Murdoch
#
On Sun, 11 Oct 2009, Mathieu Ribatet wrote:

            
Well, the recommended procedure has long been to look at the package 
PDF manual (which R CMD check leaves around for that purpose), and 
indeed this was (and still is) in the checklist in section 1.5 for 
'Writing R Extensions'.

However, please do look at *all* of text, HTML and PDF versions of the 
help, as this will help us to refine the rendering.   For example, one 
thing we have found recently is that tabs in the .Rd files are not 
being expanded as before and so alignment (especially in \usage and 
\examples sections) was off.  (We may be able to change that one 
before release, but it is an example of something that was in none of 
the main R help files and so took several weeks to spot.)