Using “cat” to write non-English characters into a .html file (in R)

前端 未结 3 1933
野的像风
野的像风 2021-01-21 08:33

Here is the code showing the problem:

myPath = getwd()
cat(\"abcd\", append = T, file =paste(myPath,\"temp1.html\", sep = \"\\\\\")) # This is fine
cat(\"
3条回答
  •  鱼传尺愫
    2021-01-21 09:07

    The problem isn’t with R (R is correctly producing UTF-8 encoded output) … it’s just that your web browser assumes the wrong encoding in the absence of an explicitly specified encoding. Just use the following snippet (from inside R) instead:

    
        
            
        
        
            שלום
        
    
    

    This specifies a correct encoding (UTF-8), and hence causes the browser to thread the following text correctly.

提交回复
热议问题