[Rd] Rd2txt: frmt() overestimates width of multi-line arguments

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Sat Jul 31 20:18:15 CEST 2021


Hi!

I wanted to use the second argument of \figure{}{} to provide a
pseudo-graphic rendition of the image and noticed that it's not centered
despite the intent to do so is visible in the code.

I traced it to a line in the frmt() function. It seems to me that
frmt() doesn't expect its input to consist of more than one line
because it sums the lengths of its components. A similar problem could
be observed in a \deqn{} consisting of multiple relatively short lines:
it would not be centered despite the available space.

A fix would be to change the width calculation:

Index: src/library/tools/R/Rd2txt.R
===================================================================
--- src/library/tools/R/Rd2txt.R        (revision 80675)
+++ src/library/tools/R/Rd2txt.R        (working copy)
@@ -356,7 +356,7 @@
     ## Use display widths as used by cat not print.
     frmt <- function(x, justify="left", width = 0L) {
         justify <- match.arg(justify, c("left", "right", "centre", "none"))
-        w <- sum(nchar(x, "width")) # copes with 0-length x
+        w <- max(nchar(c("", x), "width")) # copes with 0-length x
         if(w < width && justify != "none") {
             excess <- width - w
             left <- right <- 0L

I would like to clarify: should such small problems be raised first in
R-devel for discussion (e.g. whether it should be considered a bug)? Or
should I just file a bug in the Bugzilla and attach a patch there?

-- 
Best regards,
Ivan



More information about the R-devel mailing list