How can i specify encode in fwrite() for export csv file R?

前端 未结 4 1795
花落未央
花落未央 2021-01-13 18:19

Since fwrite() cannot apply encoding argument , how can i export csv file in specific encode as fast as fwrite() ? (fwrite()

4条回答
  •  忘掉有多难
    2021-01-13 18:47

    If you work within R,
    try this as working approach:

    # You have DT   
    # DT is a data.table / data.frame   
    # DT$text contains any text data not encoded with 'utf-8'       
    
    library(data.table)   
    DT$text <– enc2utf8(DT$text) # it forces underlying data to be encoded with 'utf-8'   
    fwrite(DT, "DT.csv", bom = T) # Then save the file using ' bom = TRUE ' 
    

    Hope that helps.

提交回复
热议问题