简体   繁体   English

Readlines()编码问题,特殊字符

[英]Problem with encoding Readlines(), special character

I have some accents in my file and I'm trying to open this file with the proper encoding, but every time I'm opening this file, my accents come up with special characters (), although I mentioned to open the file with encoding = UTF-8 我的文件中有一些重音,并且我尝试使用正确的编码打开该文件,但是每次我打开该文件时,我的重音都带有特殊字符(),尽管我提到过使用编码打开文件= UTF-8

mes_keywords_to_check <- readLines("mot cle holidays.txt", encoding='UTF-8')

Do you know what is the problem? 你知道这是什么问题吗?

I can reproduce your issue: 我可以重现您的问题:

temp <- tempfile(fileext = ".txt")

write("Ole Gunnar Solskjær", temp)

readLines(temp, encoding = "UTF-8")

[1] "Ole Gunnar Solskj\xe6r"

However, in my case it is resolved by omitting the encoding parameter in readLines (or using latin1 instead of UTF-8 ): 但是,在我的情况下,可以通过省略readLines的编码参数(或使用latin1而不是UTF-8 )来解决:

readLines(temp)
[1] "Ole Gunnar Solskjær"

readLines(temp, encoding = "latin1")
[1] "Ole Gunnar Solskjær"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM