使用R转换文件编码? (ANSI到UTF-8) [英] Convert a file encoding using R? (ANSI to UTF-8)

查看:386
本文介绍了使用R转换文件编码? (ANSI到UTF-8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将使用ANSI编码的HTML文件转换为UTF-8,使用R。



是否有工具或工具的组合可以使这个工作?



谢谢。



修改:好的,我缩小了我的问题到另一个。在这里重新发布:使用猫将非英文字符写入.html文件(在R中)

解决方案

可以使用iconv: / p>

  writeLines(iconv(readLines(tmp.html),from =ANSI_X3.4-1986,=UTF8 ),tmp2.html)

tmp2.html应该是utf-8。 >




Henrik于2015年6月编辑:

Windows的一个工作解决方案来自评论如下:

  writeLines(iconv(readLines(tmp.html),from =ANSI_X3.4 -1986,to =UTF8),
文件(tmp2.html,encoding =UTF-8))


I wish to convert an HTML file encoded in ANSI to UTF-8, using R.

Is there a tool, or a combination of tools, that can make this work?

Thanks.

Edit: o.k, I've narrowed my problem to another one. It is re-posted here: Using "cat" to write non-English characters into a .html file (in R)

解决方案

you can use iconv:

writeLines(iconv(readLines("tmp.html"), from = "ANSI_X3.4-1986", to = "UTF8"), "tmp2.html")

tmp2.html should be utf-8.


Edit by Henrik in June 2015:
A working solution for Windows distilled from the comments is as follows:

writeLines(iconv(readLines("tmp.html"), from = "ANSI_X3.4-1986", to = "UTF8"), 
           file("tmp2.html", encoding="UTF-8"))

这篇关于使用R转换文件编码? (ANSI到UTF-8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆