Read a UTF-8 text file with BOM

前端 未结 2 1151
无人共我
无人共我 2020-11-28 10:20

I have a text file with Byte order mark (U+FEFF) at the beginning. I am trying to read the file in R. Is it possible to avoid the Byte order mark?

The function

相关标签:
2条回答
  • 2020-11-28 10:40

    Have you tried read.csv(..., fileEncoding = "UTF-8-BOM")?. ?file says:

    As from R 3.0.0 the encoding ‘"UTF-8-BOM"’ is accepted and will remove a Byte Order Mark if present (which it often is for files and webpages generated by Microsoft applications).

    0 讨论(0)
  • 2020-11-28 10:46

    This was handled between versions 1.9.6 and 1.9.8 with this commit; update your data.table installation to fix this.

    Once done, you can just use fread:

    fread("file_name.csv")
    
    0 讨论(0)
提交回复
热议问题