1

I have recently updated to R-4.0.3 and am having trouble running some of my old code.

Some unicode characters seem to be "simplified" by R to the point that they change their meaning or are meaningless.

c("a ≥ b", "√2", "360°") returns [1] "a = b" "v2" "360°"

I can correctly render the symbols using their unicode codepoint, but when I do anything to the resulting character vector the special characters are not preserved.

char_str <- c("a \u2265 b", "\u221A2", "360\u00B0")

> char_str
[1] "a ≥ b" "√2"    "360°"

> data.frame(char_str)
  char_str
1    a = b
2       v2
3     360°

In previous installation of R (3.xx) the ≥ and √ were preserved when put into a data.frame. I am eventually passing a data frame to a flextable:: object to put into a .docx using officer::. I would settle for a solution that never renders the chars until the final step.

bmrn
  • 470
  • 3
  • 12
  • What does your `locale()` show? – Gregor Thomas Dec 10 '20 at 04:53
  • I can reproduce your problem on R 4.0.2. I wonder if the issue is with `print.data.frame`, if I do `d = data.frame(x = "a \u2265 b")`, `print(dd)` shows `=`, but `print(dd[[1]])` shows `≥`. So the information is still there, it's just not being printed correctly. I have a cloud machine up running 3.6.2, and it also reproduces the problem. – Gregor Thomas Dec 10 '20 at 04:58
  • Hmmm, doing some more googling, this might be known issue with Windows. See [this old Q&A on SO](https://stackoverflow.com/q/17715956/903061), and [this thread on r-devel](https://r.789695.n4.nabble.com/Unicode-display-problem-with-data-frames-under-Windows-td4707639.html). The good news is it should be fine when you put it into a .docx. – Gregor Thomas Dec 10 '20 at 05:06
  • I cannot reproduce this on R 4.0.3 on Mac. It works the same for me if either in data.frame or vector. – Ronak Shah Dec 10 '20 at 05:16

0 Answers0