Rhtml:警告:'< var>'上的转换失败在'mbcsToSbcs'中:点代替< var> [英] Rhtml: Warning: conversion failure on '<var>' in 'mbcsToSbcs': dot substituted for <var>

查看:239
本文介绍了Rhtml:警告:'< var>'上的转换失败在'mbcsToSbcs'中:点代替< var>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:



R v。2.15.1在Mac OS 10.8.2,平台x86_64-apple-darwin9.8.0 / x86_64 (64位),RStudio IDE设置为使用UTF-8作为其默认编码。操作系统还使用UTF-8。

 > Sys.getlocale(category =LC_ALL)
[1]sk_SK.UTF-8 / sk_SK.UTF-8 / sk_SK.UTF-8 / C / sk_SK.UTF-8 / sk_SK.UTF-8

目标:



从R HTML(.Rhtml)文件生成一个HTML文件,其中包含一个扩展拉丁字符的图形,如š或č。



问题:



当我点击编织HTML 时,输出如下所示:



pre> plot(1:2,main =šč)
##警告:'mbcsToSbcs'中'šč'的转换失败:点代替
##
##警告:'mbcsToSbcs'中'šč'上的转换失败:点替换
##
##警告:'mbcsToSbcs'中'šč'的转换失败:点代替
##
##警告:'mbcsToSbcs'中'šč'上的转换失败:点代替
##< 8d>
**尽管发出警告,但使用正确的字符。**

问题:



是什么原因导致问题及解决方法?我至少可以摆脱在结果文件中显示的警告?



无偏的注释:



我一直在寻找一两个解决方案,发现了很多类似的案例,并尝试了许多不同的潜在解决方案(许多与PDF输出相关的解决方案,如果我使用只是一样



2012年11月9日编辑



使用@metsoquoia建议的 Encoding()的解决方案可以正常工作,但是考虑到需要打印代码,优选没有该功能,我更喜欢提供的解决方案由@nograpes使用函数 pdf.options()



尽管如此, p>

 <! -  begin.rcode 
pdf.options(encoding ='ISOLatin2.enc')
plot(cars,main =Ťažký)
end.rcode - >

产生相同的警告,

 <! -  begin.rcode 
pdf.options(encoding ='ISOLatin2.enc')
end.rcode - >

<! - begin.rcode
plot(cars,main =Ťažký)
end.rcode - >

按预期工作。 为什么是这样的?我认为在R中运行命令时,年表是重要的。



所以,为了我的目的,确定的解决方案是put

 <! -  begin.rcode echo =FALSE
pdf.options(encoding ='ISOLatin2 .enc')
end.rcode - >每个代码开头的

解决方案

@水杉的答案有效,但是我想补充一点。如果将PDF选项设置为不同的编码,则不需要将所有输出文本包含在 Encoding 中。在点击编织HTML 之前运行此操作:

  pdf.options(encoding ='ISOLatin2.enc') 

Ripley谈论编码问题,特别是与在这里发布,这可能是感兴趣的。值得注意的是,这种错误在Windows上不会以相同的方式发生,因为编码以完全不同的方式处理。



其他语言可能需要使用其他编码文件,但这似乎适用于斯洛伐克语。


Environment:

R v. 2.15.1 on Mac OS 10.8.2, platform x86_64-apple-darwin9.8.0/x86_64 (64-bit), with RStudio IDE which is set to use UTF-8 as its default encoding. The OS also uses UTF-8.

> Sys.getlocale(category = "LC_ALL")
[1] "sk_SK.UTF-8/sk_SK.UTF-8/sk_SK.UTF-8/C/sk_SK.UTF-8/sk_SK.UTF-8"

Objective:

Generate an HTML file from the R HTML (.Rhtml) file, containing a plot with extended latin characters, such as š or č.

Problem:

When I click on Knit HTML, the output looks like this:

plot(1:2, main = "šč")
## Warning: conversion failure on 'šč' in 'mbcsToSbcs': dot substituted for
## 
## Warning: conversion failure on 'šč' in 'mbcsToSbcs': dot substituted for
## 
## Warning: conversion failure on 'šč' in 'mbcsToSbcs': dot substituted for
## 
## Warning: conversion failure on 'šč' in 'mbcsToSbcs': dot substituted for
## <8d>
**Plot with correct characters despite the warnings.**

Question:

What causes the problem and how to solve it? How can I at least get rid of the warnings which do show in the resulting file?

Hopeless note:

I have been searching for a solution for the past hour or two, found many similar cases and tried many different potential solutions (many related to PDF output, which is cocked up the same way if I use just Sweave), and now I am literally hopeless.

Edit on 9 November 2012:

The solution using Encoding() suggested by @metasequoia does work, but considering the need to print the code as well, preferably without that function, I prefer the solution provided by @nograpes using the function pdf.options().

It is interesting, though, that while

<!--begin.rcode
pdf.options(encoding='ISOLatin2.enc')
plot(cars, main="Ťažký")
end.rcode-->

produces the same warnings,

<!--begin.rcode
pdf.options(encoding='ISOLatin2.enc')
end.rcode-->

<!--begin.rcode
plot(cars, main="Ťažký")
end.rcode-->

works as expected. Why is that? I thought that chronology is all that matters when running commands in R.

So, the definite solution for my purposes is to put

<!--begin.rcode echo="FALSE"
pdf.options(encoding='ISOLatin2.enc')
end.rcode-->

in the beginning of each of my codes.

解决方案

The answer from @metasequoia works, but I wanted to add a few points. If you set the PDF options to a different encoding you won't need to wrap all your output text in Encoding. Run this before clicking Knit HTML:

pdf.options(encoding='ISOLatin2.enc')

Ripley talks about encoding issues, especially as the relate to PDFs, in a post here, and it may be of interest. Notably, this error will not occur in the same way on Windows, because encoding is handled in a completely different way.

A different encoding file may be needed for other languages, but this seems to work for Slovak.

这篇关于Rhtml:警告:'&lt; var&gt;'上的转换失败在'mbcsToSbcs'中:点代替&lt; var&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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