Hello R-devel!
Here's an Rd file that produces a large empty area when converted to
HTML:
\name{repro}
\title{title}
\description{description}
\details{
Hello
\Sexpr[stage=build,results=hide]{
invisible(NULL)
invisible(NULL)
invisible(NULL)
invisible(NULL)
invisible(NULL)
invisible(NULL)
invisible(NULL)
invisible(NULL)
invisible(NULL)
invisible(NULL)
invisible(NULL)
"" # workaround: remove results=hide and use the return value
}
}
This seems to happen because \Sexpr gets expanded to \verb{ as many
newlines as there were code lines } by processRdChunk, by first storing
a newline for each line of the code:
https://github.com/wch/r-source/blob/d7a4ed9aaeee1f57c3c165aefa08b8d69dfe59fa/src/library/tools/R/RdConv2.R#L257
...and then the newlines get translated to \verb because res is
not empty:
https://github.com/wch/r-source/blob/d7a4ed9aaeee1f57c3c165aefa08b8d69dfe59fa/src/library/tools/R/RdConv2.R#L332
As long as Rd above doesn't stem from my misuse of \Sexpr, I would like
to propose the following patch, which seems to fix the problem:
Index: src/library/tools/R/RdConv2.R
==================================================================---
src/library/tools/R/RdConv2.R (revision 80675)
+++ src/library/tools/R/RdConv2.R (working copy)
@@ -329,6 +329,8 @@
}
} else if (options$results == "text")
res <- tagged(err, "TEXT")
+ else if (options$results == "hide")
+ res <- tagged("", "COMMENT")
else if (length(res)) {
res <- lapply(as.list(res), function(x) tagged(x, "VERB"))
res <- tagged(res, "\\verb")
There are probably other ways of fixing this problem, e.g. by only
populating res if options$results != "hide" or only appending newlines
if res is non-empty.
--
Best regards,
Ivan
Martin Maechler
2021-Jul-31 20:14 UTC
[Rd] \Sexpr[results=hide] produces \verb{ newlines }
>>>>> Ivan Krylov >>>>> on Thu, 29 Jul 2021 17:48:38 +0200 writes:> Hello R-devel! > > Here's an Rd file that produces a large empty area when converted to > HTML: > > \name{repro} > \title{title} > \description{description} > \details{ > Hello > \Sexpr[stage=build,results=hide]{ > invisible(NULL) > invisible(NULL) > invisible(NULL) > invisible(NULL) > invisible(NULL) > invisible(NULL) > invisible(NULL) > invisible(NULL) > invisible(NULL) > invisible(NULL) > invisible(NULL) > "" # workaround: remove results=hide and use the return value > } > } > > This seems to happen because \Sexpr gets expanded to \verb{ as many > newlines as there were code lines } by processRdChunk, by first storing > a newline for each line of the code: > > https://github.com/wch/r-source/blob/d7a4ed9aaeee1f57c3c165aefa08b8d69dfe59fa/src/library/tools/R/RdConv2.R#L257 > > ...and then the newlines get translated to \verb because res is > not empty: > > https://github.com/wch/r-source/blob/d7a4ed9aaeee1f57c3c165aefa08b8d69dfe59fa/src/library/tools/R/RdConv2.R#L332 > > As long as Rd above doesn't stem from my misuse of \Sexpr, I would like > to propose the following patch, which seems to fix the problem: > > Index: src/library/tools/R/RdConv2.R > ==================================================================> --- src/library/tools/R/RdConv2.R (revision 80675) > +++ src/library/tools/R/RdConv2.R (working copy) > @@ -329,6 +329,8 @@ > } > } else if (options$results == "text") > res <- tagged(err, "TEXT") > + else if (options$results == "hide") > + res <- tagged("", "COMMENT") > else if (length(res)) { > res <- lapply(as.list(res), function(x) tagged(x, "VERB")) > res <- tagged(res, "\\verb") > > There are probably other ways of fixing this problem, e.g. by only > populating res if options$results != "hide" or only appending newlines > if res is non-empty.Thank you, Ivan, for the example and patch, I have implemented a version of your patch in my local copy of R-devel and tested your example, also with Rd2latex() .. interestingly Rd2txt() does not produce the extra new lines even without your patch. I plan to commit your proposal after the weekend unless has reasons against that. Best regards, Martin
Hello Martin, On Sat, 31 Jul 2021 22:14:17 +0200 Martin Maechler <maechler at stat.math.ethz.ch> wrote:> I have implemented a version of your patch in my local copy of > R-devel and tested your example, also with Rd2latex() .. > interestingly Rd2txt() does not produce the extra new lines > even without your patch.That's interesting, indeed. I think that flushBuffer() is responsible for collapsing multiple blank lines into one in that case, but they do get preserved in the buffer up to before that.> I plan to commit your proposal after the weekend unless has > reasons against that.Thanks for the review! -- Best regards, Ivan