[R-pkg-devel] help fixing CRAN package sos-now fails on GitHub

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue May 23 12:53:56 CEST 2023


>>>>> Duncan Murdoch 
>>>>>     on Mon, 22 May 2023 15:38:10 -0400 writes:

    > On 22/05/2023 3:07 p.m., Ivan Krylov wrote:
    >> I fed your vignette to R CMD Sweave, and here's the
    >> relevant fragment from the resulting *.tex file:
    >> 
    >>> This returned a {\tt "findFn"} object identifying 405
    >>> help pages.  When this was run while preparing this
    >>> manuscript, the sixth row was {\tt pspline_checker} in
    >>> the \pkg{JOPS} package, which has a {\tt Score} of
    >>> 47. (On another day, the results could be different,
    >>> because CRAN changes over time.)  This was the sixth row
    >>> in this table, because it is in the \pkg{JOPS} package,
    >>> which had a total of 54 help pages matching the search
    >>> term, but this was the only one whose name matched the
    >>> {\tt pattern} passed to {\tt grepFn}.
    >> 
    >> This corresponds to the following part of the vignette:
    >> 
    >>> This returned a {\tt "findFn"} object identifying
    >>> \Sexpr{nrow(g)} help pages.  When this was run while
    >>> preparing this manuscript, the sixth row was {\tt
    >>> \Sexpr{gFunc6}} in the \pkg{\Sexpr{gPac6}} package,
    >>> which has a {\tt Score} of \Sexpr{gScore6}.
    >> 
    >> So, you need to escape the underscores in
    >> gFunc6. Probably not gPac6 because underscores are not
    >> allowed in package names.
    >> 

    > Nice find.  Just in case Spencer has trouble with escaping
    > the escapes, I think he should change

    >    "{\tt \Sexpr{gFunc6}}"

    > to

    >    "{\tt \Sexpr{sub("_", "\\\\_", gFunc6)}}

    > Even better would be to write a little function
    > "sanitizeForLatex" that did this and any other necessary
    > changes, and call that.

Yes, indeed (2 x).

If I grep the base R package sources, I find three occurrences
of something like the above:

grep --color -nH --null -e 'sub *(.*\\\\_' */R/*.R

 tools/R/Rd2latex.R:295:        x <- fsub("\\_", "_", x)
 tools/R/Rd2latex.R:303:        x <- fsub("\\_", ".Rul.", x)
 tools/R/Rd.R:681:    txt <- gsub("\\_", "_", txt, fixed=TRUE)

all of which do the transformation in the other direction
(because *.Rd in those cases already *is* LaTeX-alike, and needs
 to convert for non-LaTeX use).

Note that the last one gives a hint to be more general --- gsub()
also working a.g. for 'parse_me_not' ---
*and* possibly faster (fixed=TRUE)  leading to

     "{\tt \Sexpr{gsub("_", "\\\\_", gFunc6, fixed=TRUE)}}

Martin



More information about the R-package-devel mailing list