1

I have imported an Excel (xlsx) file using the readxl package in R. One of the columns, labeldata, that is imported into R contains labels for other data contained in the file, so it consists of character data such as ≥65 years old. When I print this labeldata to the console the value for "greater than or equal to 65 years old" is properly displayed as ≥65 years old. However, when I try to combine this column with other columns (using cbind or other methods), the greater than or equal to sign () is converted to an equal sign (=). I tried to dput the labeldata object to a text file, to include in this post, but when I do so, the greater than or equal sign is converted to an equal sign there as well.

Here's the best toy example I can come up with that kind of explains what I'm seeing:

labeldata="≥ 65 years"
print(labeldata)
[1] "= 65 years"

The problem with this example, of course, is that I've simply typed in the label and could avoid the conversion issue by typing in labeldata="\u2265 65 years", but in my real work, I'm not typing in this infomration, but importing the data from Excel.

I'm guessing this is some sort of encoding issue, but is there any way to prevent the label from converting to an equal sign and to preserve the original label?

Updated relevant information

I am using Windows 10 x64 OS, with R Studio, but I've verified the problem exists within just R. I have this problem in R 3.2.3 and R 3.6.1.

I've also noticed that while this works without any problem:

labeldata = "\u2265 65 years"
labeldata
[1] "≥ 65 years"

Converting to a dataframe causes the problem to reappear:

labeldata = "\u2265 65 years"
labeldata
[1] "≥ 65 years"
data.frame(labeldata)
labeldata
1 = 65 years
StatsStudent
  • 1,384
  • 2
  • 10
  • 28
  • I cannot reproduce this, with me it prints `[1] "≥ 65 years"`. And why `rep`? `c()` or, in the case of just one string, no function call, `labeldata = "≥ 65 years"` would do it. See the help page `?rep`. – Rui Barradas Oct 06 '19 at 15:44
  • Same, have been testing and can't get to reproduce either. – caldwellst Oct 06 '19 at 15:44
  • @Rui Barradas, sorry for the rep. That was a mistake left over from making a toy example (I've deleted "rep" in my code above). I'm not sure if it's relevant or not, but I'm using R studio Version 1.2.1568 with R 3.6.1. – StatsStudent Oct 06 '19 at 15:50
  • Updating my previous comment. I can confirm that this behavior also exists in just R, with R version 3.2.3, so I think I can rule out RStudio. – StatsStudent Oct 06 '19 at 15:52
  • Interestingly enough, it seems that this problem is avoided by converting the vector to a dployr tbl. – StatsStudent Oct 06 '19 at 17:24
  • 2
    I'll counter to @RuiBarradas and @caldwellst, and confirm that i can reproduce the error while running Windows 10 (up-to-date), R-3.6.1 build 17134 on a clean session. This happens in both `R` and `R-studio`, and as such is not restricted to a single IDE. – Oliver Oct 06 '19 at 17:39
  • 1
    @Oliver OK, I'm on Ubuntu 19.04, so maybe that's why I cannot reproduce it. – Rui Barradas Oct 06 '19 at 17:41
  • 1
    Ubuntu 18.04 here. I can't reproduce the problem. The symbol is properly displayed in both R and RStudio. Could it be a windows problem? – PavoDive Oct 06 '19 at 20:59
  • The fact that I can avoid the problem by using `dplyr`'s `tbl_df` in Windows, along with the other reports here, makes me think there's something going on with base `R` for Windows. – StatsStudent Oct 06 '19 at 22:08

0 Answers0