[R] Printing special characters

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Mon Jan 16 11:15:45 CET 2023


>>>>> Rui Barradas 
>>>>>     on Mon, 16 Jan 2023 08:46:43 +0000 writes:

    > Às 08:31 de 16/01/2023, Jeff Newmiller escreveu:
    >> Use the Cairo PDF device?
    >> 
    >> On January 16, 2023 12:18:48 AM PST, Dennis Fisher
    >> <fisher using plessthan.com> wrote:
    >>> R 4.2.2 OS X
    >>> 
    >>> Colleagues
    >>> 
    >>> A file that I have read includes strings like this:
    >>> "EVENT ≥ 30 sec" When I include the string in a graphic
    >>> using: mtext(STRING, …)  it appears as: "EVENT ... 30
    >>> sec"
    >>> 
    >>> Is there a simple work-around (short of reformatting all
    >>> the strings, then using plotmath)?
    >>> 
    >>> Dennis
    >>> 
    >>> Dennis Fisher MD P < (The "P Less Than" Company) Phone /
    >>> Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com
    >>> 
    >>> ______________________________________________
    >>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and
    >>> more, see https://stat.ethz.ch/mailman/listinfo/r-help
    >>> PLEASE do read the posting guide
    >>> http://www.R-project.org/posting-guide.html and provide
    >>> commented, minimal, self-contained, reproducible code.
    >> 
    > Hello,

    > I had no problems with

    > X11()
    > plot(1,1, pch = "") 
    > text(1, 1, "EVENT ≥ 30 sec")
    > #dev.off()

Yes, for me too.
X11() *is*  by default the "X11cairo" device and that works, the
same as the "Cairo PDF" device that Jeff mentioned above.

Indeed,
  cairo_pdf("utf8-ex.pdf")  # works nicely

whereas  pdf("utf8-ex.pdf") does not {for me, with default font
families etc}, but rather shows the "..." instead.

*and* gives warnings during the plot
  conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for <e2>
  conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for <89>
  conversion failure on 'EVENT ≥ 30 sec' in 'mbcsToSbcs': dot substituted for <a5>

BTW, a simple one liner for testing is

   plot(1, type="n", axes=FALSE, main = "EVENT ≥ 30 sec")

Note that help(pdf)  contains

   See Also:

        pdfFonts, pdf.options, embedFonts, Devices, postscript.

        cairo_pdf and (on macOS only) quartz for other devices that
        can produce PDF.

        More details of font families and encodings and especially
        handling text in a non-Latin-1 encoding and embedding fonts can be
        found in

        Paul Murrell and Brian Ripley (2006).  “Non-standard fonts in
        PostScript and PDF graphics.” _R News_, *6*(2), 41-47.
        <https://www.r-project.org/doc/Rnews/Rnews_2006-2.pdf>.

-
Martin

    > Hope this helps,
    > Rui Barradas



More information about the R-help mailing list