我在Windows 7 64位上使用R 2.15.0.我想将unicode(CJK)文本输出到文件.
以下代码显示了发送到UTF-8文件连接上的Unicode字符如何不能正常工作(I):
rty <- file("test.txt",encoding="UTF-8")
write("?", file=rty)
close(rty)
rty <- file("test.txt",encoding="UTF-8")
scan(rty,what=character())
close(rty)
Run Code Online (Sandbox Code Playgroud)
如扫描输出所示:
Read 1 item
[1] "<U+5728>"
Run Code Online (Sandbox Code Playgroud)
该文件不是用UTF字符本身编写的,而是某种符合ANSI标准的回退.我可以让它第一次正常工作(即使用其中包含"在"的文本文件),或者我可以使用一些额外的魔法将输出转换为Unicode,并使用正确的字符替换代码字符串吗?
谢谢.
[更多信息:相同的代码在Cygwin,R 2.14.2中正常运行,而Win7上的2.14.2也被破坏.这是在我的某个地方吗?]
我无法理解我错过了一些明显的东西.是否有更清晰或更惯用的方式来执行以下功能?
closest.preceding <- function(candidates, limit) {
# return the value in candidates that is closest to but less than the limit
return(limit - min(limit-candidates[candidates < limit]))
}
Run Code Online (Sandbox Code Playgroud)
感谢您的任何见解.