使用“猫”将非英文字符写入.html文件(在R中) [英] Using "cat" to write non-English characters into a .html file (in R)

查看:124
本文介绍了使用“猫”将非英文字符写入.html文件(在R中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是显示问题的代码:

  myPath = getwd()
cat(abcd, append = T,file = paste(myPath,temp1.html,sep =\\))#这是好的
cat(< BR />< BR />< ; BR />,append = T,file = paste(myPath,temp1.html,sep =\\))#这是好的
cat(שלום,append = F ,file = paste(myPath,temp1.html,sep =\\))#当在Windows 7上使用谷歌浏览器打开html时,该文本会出现乱码。
cat(שלום, append = F,file = paste(myPath,temp1.txt,sep =\\))#但是如果我在文本编辑器中打开这个文件 - 文本看起来不错

#HTML文件夹中的文本看起来好像我在哪里运行R:
(x < - iconv(שלום,from =CP1252,to =UTF8))
#但是,如果我在哪里尝试并将其放入文件中,它不会放入任何内容:
cat(x,append = T,file = paste(myPath,temp1.html,sep = \\))#empty

编辑:
我也试过使用下面的编码(没有成功)

  ff < -file(paste(myPath,temp1.html,sep =\\\),encoding =CP1252)
cat(שלום,append = F,file = ff)
ff< -file(paste(myPath,temp1.html,sep =\\\),encoding =utf-8)
cat(שלום,append = F, file = ff)
ff< -file(paste(myPath,temp1.html,sep =\\\),encoding =ANSI_X3.4-1986)
cat( (paste(myPath,temp1.html,sep =\\),encoding =iso8859-8)$ b $ append = F,file = ff)
ff< $ b cat(שלום,append = F,file = ff)

有什么建议吗?谢谢。

解决方案

您的代码有点多余。第5行是 temp1.txt 一个错字( .html )?无论如何,也许你应该在< meta> 标记内设置 charset



这是一个例子:

 < html> 
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8>
< / head>
< body>
cat(abcd)
cat(< BR />< BR />< BR />)
cat( (x) - iconv(שלום,from =CP1252,to =UTF8))
cat(שלום)

- %>
< / body>
< / html>

这是一个 brew 代码,所以如果你继续, brew 它,你会得到正确的回应。长话短说,关键字是 charset


Here is the code showing the problem:

myPath = getwd()
cat("abcd", append = T, file =paste(myPath,"temp1.html", sep = "\\")) # This is fine
cat("<BR/><BR/><BR/>", append = T, file =paste(myPath,"temp1.html", sep = "\\")) # This is fine
cat("שלום", append = F, file =paste(myPath,"temp1.html", sep = "\\")) # This text gets garbled when the html is opened using google chrome on windows 7.
cat("שלום", append = F, file =paste(myPath,"temp1.txt", sep = "\\")) # but if I open this file in a text editor - the text looks fine

# The text in the HTML folder would look as if I where to run this in R:
(x <- iconv("שלום", from = "CP1252", to = "UTF8") )
# But if I where to try and put it into the file, it wouldn't put anything in:
cat(x, append = T, file =paste(myPath,"temp1.html", sep = "\\")) # empty

Edit: I've also tried using the following encoding (without success)

ff <-file(paste(myPath,"temp1.html", sep = "\\"), encoding="CP1252")
cat("שלום", append = F, file =ff)
ff<-file(paste(myPath,"temp1.html", sep = "\\"), encoding="utf-8")
cat("שלום", append = F, file =ff)
ff<-file(paste(myPath,"temp1.html", sep = "\\"), encoding="ANSI_X3.4-1986")
cat("שלום", append = F, file =ff)
ff<-file(paste(myPath,"temp1.html", sep = "\\"), encoding="iso8859-8")
cat("שלום", append = F, file =ff)

Any suggestions? Thanks.

解决方案

Your code is a bit redundant. Is temp1.txt on line 5 a typo (.html)? Anyway, perhaps you should set charset within <meta> tag.

Take this as an example:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
cat("abcd")
cat("<BR/><BR/><BR/>")
cat("שלום")
cat("שלום")
(x <- iconv("שלום", from = "CP1252", to = "UTF8") )
cat(x)
-%>
</body>
</html>

It is a brew code, so if you go ahead and brew it, you'll get correct response. Long story short, the keyword was charset.

这篇关于使用“猫”将非英文字符写入.html文件(在R中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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