R prints UTF-8 code to data.frames on Windows Rstudio platform

When UTF-8 characters are present in the data frame, it will not display correctly.

For example, the following is true:

> "\U6731"
[1] "朱"

      

But when I put that in a dataframe and print it, here it comes:

> data.frame(x="\U6731")
         x
1 <U+6731>

      

So I believe it has nothing to do with encoding issues.

Is there any direct way to print

instead <U+6731>

.

I need to use Windows in a company, so using Linux is not possible for me.

+3


source to share


2 answers


The corpus library has a workaround for this error. Or do this:

library(corpus)
df <- data.frame(x = "\U6731")
print.corpus_frame(df)

      



Or do the following:

class(df) <- c("corpus_frame", "data.frame")
df

      

+1


source


You are right, calling the entire dataframe, it will output the codes for UTF-8 characters:

> data.frame(x="\U6731")
         x
1 <U+6731>

      

But if you call columns or rows it will print nicely:



# through the column name
> data.frame(x="\U6731")$x
[1] 朱
Levels: 朱

# through the column index
> data.frame(x="\U6731")[,1]
[1] 朱
Levels: 朱

# through the row index
> data.frame(x="\U6731")[1,]
[1] 朱
Levels: 朱

      

Not sure if this helps. Could you elaborate on why and how exactly you need to output these characters?

0


source







All Articles