Why do some Unicode characters display in matrices, but not data frames in R?

前端 未结 2 1306
萌比男神i
萌比男神i 2020-11-30 03:22

For at least some cases, Asian characters are printable if they are contained in a matrix, or a vector, but not in a data.frame. Here

2条回答
  •  暖寄归人
    2020-11-30 04:09

    I hate to answer my own question, but although the comments and answers helped, they weren't quite right. In Windows, it doesn't seem like you can set a generic 'UTF-8' locale. You can, however, set country-specific locales, which will work in this case:

    Sys.setlocale("LC_CTYPE", locale="Chinese")
    q2 # Works fine
    #  q
    #1 天
    

    But, it does make me wonder why exactly format seems to use the locale; I wonder if there is a way to have it ignore the locale in Windows. I also wonder if there is some generic UTF-8 locale that I don't know about on Windows.

提交回复
热议问题