[R] Printing special characters
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon Jan 16 12:02:01 CET 2023
Às 10:15 de 16/01/2023, Martin Maechler escreveu:
>>>>>> 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
Hello,
I can confrim this behavior with cairo_pdf(), it works as expected
printing "EVENT ≥ 30 sec".
But with pdf() I get an equal sign "EVENT = 30 sec" and no errors.
Full code:
cairo_pdf("~/Temp/cairo_pdf_utf8-ex.pdf") # works
plot(1,1, pch = "")
text(1, 1, "EVENT ≥ 30 sec")
dev.off()
# null device
# 1
pdf("~/Temp/pdf_utf8-ex.pdf") # prints "=", no warnings
plot(1,1, pch = "")
text(1, 1, "EVENT ≥ 30 sec")
dev.off()
# null device
# 1
sessionInfo()
# R version 4.2.1 (2022-06-23 ucrt)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 22621)
#
# Matrix products: default
#
# locale:
# [1] LC_COLLATE=Portuguese_Portugal.utf8 LC_CTYPE=Portuguese_Portugal.utf8
# [3] LC_MONETARY=Portuguese_Portugal.utf8 LC_NUMERIC=C
# [5] LC_TIME=Portuguese_Portugal.utf8
#
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base
#
# loaded via a namespace (and not attached):
# [1] compiler_4.2.1
#
Also, nice trick to print the text as plot title, I will remember that
one-liner.
Hope this helps,
Rui Barradas
More information about the R-help
mailing list