Paul Sherliker
2025-Feb-19 11:36 UTC
[R] Code \255 no longer working to produce a short dash in base R PDF graphs
I make graphs, in large quantities, for perfectionists. My bosses do not like the results of text like 'baseline-defined' in graphs; they feel that the resulting dash is too long. For many years, I have been in the habit of producing graphs with shorter dashes as follows: pdf("myfile.pdf") plot(1, 10) text(1, 11, "baseline\255defined") text(1, 9, "done") graphics.off() They like that dash - but I never knew what it was called. Recently work updated my PC to the latest version of Windows, and, perforce, I updated to the latest version of R (4.4.2). (So I'm not sure which change caused my problem; in any case I cannot practically go back for either.) The code above now fails, with the error message: Error in text.default(1, 11, "baseline\xaddefined") : invalid input 'baseline> text(1, 9, "done") I'm trying various Unicode values, currently settling on \U{2010}, but I'm getting complaints about the length of my dashes. I'm no expert on fonts, and perhaps I've missed a Unicode value that would be perfect. Is there a way to get back to what I had, without resorting to more complicated code, please? Thank you for looking at my deeply obscure niche problem! Paul [[alternative HTML version deleted]]
Ivan Krylov
2025-Feb-20 12:48 UTC
[R] Code \255 no longer working to produce a short dash in base R PDF graphs
? Wed, 19 Feb 2025 11:36:15 +0000 Paul Sherliker via R-help <r-help at r-project.org> ?????:> text(1, 11, "baseline\255defined") > text(1, 9, "done") > graphics.off() > > They like that dash - but I never knew what it was called. > > Recently work updated my PC to the latest version of Windows, and, > perforce, I updated to the latest version of R (4.4.2).Nowadays, the session encoding on appropriately new versions of Windows is UTF-8 [*]. Previously, the native encoding of the R session corresponded to the ANSI encoding of your computer, most likely CP1252. Let's see what does \255 mean in that encoding: iconv('\255', 'CP1252', '') |> utf8ToInt() |> as.hexmode() # [1] "ad" Does '\uad' work for you? -- Best regards, Ivan [*] https://blog.r-project.org/2020/05/02/utf-8-support-on-windows/index.html
Duncan Murdoch
2025-Feb-20 13:37 UTC
[R] Code \255 no longer working to produce a short dash in base R PDF graphs
On 2025-02-19 6:36 a.m., Paul Sherliker via R-help wrote:> I make graphs, in large quantities, for perfectionists. > > My bosses do not like the results of text like 'baseline-defined' in graphs; they feel that the resulting dash is too long. > > For many years, I have been in the habit of producing graphs with shorter dashes as follows: > > pdf("myfile.pdf") > plot(1, 10) > text(1, 11, "baseline\255defined") > text(1, 9, "done") > graphics.off() > > They like that dash - but I never knew what it was called. > > Recently work updated my PC to the latest version of Windows, and, perforce, I updated to the latest version of R (4.4.2). > (So I'm not sure which change caused my problem; in any case I cannot practically go back for either.) > > The code above now fails, with the error message: > Error in text.default(1, 11, "baseline\xaddefined") : invalid input 'baseline> text(1, 9, "done") > > I'm trying various Unicode values, currently settling on \U{2010}, but I'm getting complaints about the length of my dashes. > I'm no expert on fonts, and perhaps I've missed a Unicode value that would be perfect.This web page: https://www.compart.com/en/unicode/category/Pd lists a lot of choices. You didn't say what the complaints were ("too long"? "too short"?), so I can't recommend what to try other than \U{2010}, but there is a big variety of choices there. Duncan Murdoch> > Is there a way to get back to what I had, without resorting to more complicated code, please? > > Thank you for looking at my deeply obscure niche problem! > > Paul > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.