[R] bgroup not rendering properly

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue Dec 13 11:55:01 CET 2022


>>>>> Martin Maechler 
>>>>>     on Tue, 13 Dec 2022 11:02:23 +0100 writes:

>>>>> Jinsong Zhao 
>>>>>     on Tue, 13 Dec 2022 17:07:00 +0800 writes:

    >> I don

Jinsong started on top and I did not see his continuation
at the very bottom
(so scroll down there!)


    >> On 2022/12/13 10:13, Derek Ogle wrote:
    >>> bgroup() from plotmath does not render properly for
    >>> me. For example
    >>> 
    >>> plot(0,xlim=c(0,1),ylim=c(0,1))
    >>> text(0.3,0.5,expression(bgroup('(',atop(x,y),')')))
    >>> text(0.7,0.5,expression(group('(',atop(x,y),')')))

    > Almost surely a Windows-only problem i.e. bug, See also
    > the bug fixed yesterday, PR#18440,
    > https://bugs.r-project.org/show_bug.cgi?id=18440

    > Note that "rendering" of graphics strongly depends on your
    > graphics device (people no longer learn about nowadays).
    > Hence, use

    >    .Device or dev.cur()

    > and report that along with your session info.

    > I bet that you will see that after

    > png("bgroup.png") # or pdf("bgroup.pdf")
    > expression(bgroup('(',atop(x,y),')') dev.off()

    > the resulting PNG or PDF will look fine, even on Windows
    > in R 4.2.2.

    > Martin

    >>> 
    >>> and
    >>> 
    >>> library(ggplot2) ggplot(mtcars, aes(wt, mpg)) +
    >>> annotate("text", x=2.5, y=25,
    >>> label="bgroup('(',atop(x,y),')')", parse=TRUE) +
    >>> annotate("text", x=3.5, y=25,
    >>> label="group('(',atop(x,y),')')", parse=TRUE)
    >>> 
    >>> both show a proper (though ugly) result from group()
    >>> (the second text() or annotation()) but unrecognizable
    >>> characters (rather than large parentheses) from
    >>> bgroup().
    >>> 
    >>> This problematic result occurred for me when using
    >>> v4.2.2, but not when using 4.2.0, 4.1.2, 4.1.0, or
    >>> 4.0.5. My sessionInfo is further below.
    >>> 
    >>> I did ask this on stackoverflow
    >>> <https://stackoverflow.com/questions/74738827/bgroup-does-not-render-properly-on-ggplot>
    >>> where the resulting figures can be seen.
    >>> 
    >>> 
    >>> ----
    >>> R version 4.2.2 (2022-10-31 ucrt) Platform:
    >>> x86_64-w64-mingw32/x64 (64-bit) Running under: Windows
    >>> 10 x64 (build 19044)
    >>> 
    >>> Matrix products: default
    >>> 
    >>> locale: [1] LC_COLLATE=English_United States.utf8 [2]
    >>> LC_CTYPE=English_United States.utf8 [3]
    >>> LC_MONETARY=English_United States.utf8 [4] LC_NUMERIC=C
    >>> [5] LC_TIME=English_United States.utf8
    >>> 
    >>> attached base packages: [1] stats graphics grDevices
    >>> utils datasets methods base
    >>> 
    >>> loaded via a namespace (and not attached): [1]
    >>> compiler_4.2.2 tools_4.2.2

    >> I don't see any problem, especially when outputing the
    >> plot to a pdf file.

    >> Best, Jinsong

Interesting, so even on Windows, the problem does not always
show evidently.
The pdf is clearly working (see my own first reply),
but then, could it be that there's a difference between Jinsong's
computer or his way of using R and the others, Rui and Derek ?

The ugly rectangles are typically shown for characters for which
the graphics device does not find any fonts...
and in principle there may be subtle differences.

Is it always within RStudio which I think *does* use R's own
"graphapp" based Windows device. 
It that's still true, then same would probably happen within
bare RGui.

For me, on a (2016!) Windows terminal server,
the bgroup() things also work nicely, at least if I use R from
ESS (-> Rterm). 

Martin



More information about the R-help mailing list