环境:
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,输出看起来像这样:
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.**
题:
是什么导致问题以及如何解决?我怎样才能至少摆脱结果文件中显示的警告?
无望的说明:
我一直在寻找过去一两个小时的解决方案,发现了许多类似的案例,并尝试了许多不同的潜在解决方案(许多与PDF输出相关,如果我只使用Sweave,它会以相同的方式竖起),现在我确实绝望。
2012年11月9日编辑:
解决方案使用 Encoding()
由@metasequoia建议确实有效,但考虑到打印代码的需要,最好没有该功能,我更喜欢@nograpes使用该功能提供的解决方案 pdf.options()
。
尽管如此,有趣的是
<!--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中运行命令时,年表是最重要的。
因此,我的目的的明确解决方案是
<!--begin.rcode echo="FALSE"
pdf.options(encoding='ISOLatin2.enc')
end.rcode-->
在我的每个代码的开头。