问题描述
python 代码:
import rpy2.robjects as robjects
rCommand='''gender <- c("남자", "남자", "남자", "여자", "여자", "여자", "여자", "여자")
age <- c(23, 25, 27, 29, 31, 33, 35, 37)
outdf <- data.frame(gender, age)
'''
robjects.r(rCommand)
resultDf_r=robjects.globalenv["outdf"]
print type(resultDf_r)
韩文字符使 python.exe 被杀死.
Korean characters makes the python.exe killed.
在 R 命令终端中,上面的rCommand"运行良好.
In R command terminal, "rCommand" above works well.
我找不到任何解决方案.
I couldn't find any solution.
任何帮助将不胜感激.
我的环境:window 7 x64,python 2.7.8 x64,rpy2 2.5.4,R 3.1.2
my env: window 7 x64, python 2.7.8 x64, rpy2 2.5.4, R 3.1.2
推荐答案
在撰写本文时,遗憾的是没有 rpy2
for windows 的官方支持.您提供的代码片段在 Linux 上运行良好.
At the time of writing, there is unfortunately no official support of rpy2
for windows. The code snippet you are providing is working fine on Linux.
您的选择可能是:
在 Linux VM(或容器 - MS 已宣布支持 Docker)中运行您的代码
run your code in a Linux VM (or container - MS has announced to be backing Docker)
提交 rpy2 的补丁
submit a patch for rpy2
在 rpy2
的 bitbucket 页面上提交错误报告,希望这能转化为某人的补丁
file a bug report on the bitbucket page for rpy2
hoping that this translates into a patch by someone
评论表明帮助 Python 2.7 进行编码可能会有所帮助(不保证 - 一切都在 Linux 上运行,所以这可能是特定于 Windows 的).一个字符串可以被明确指定为 unicode(注意 '''
之前的前缀 u
):
The comments suggest that helping out Python 2.7 with encoding might help (no promise - everything is working on Linux so this might be Windows-specific). A string can be explicitly specified to be in unicode with (note the prefix u
before '''
):
rCommand=u'''
gender <- c("남자", "남자", "남자", "여자", "여자", "여자", "여자", "여자")
age <- c(23, 25, 27, 29, 31, 33, 35, 37)
outdf <- data.frame(gender, age)
'''
robjects.r(rCommand)
这篇关于rpy2 : 韩文字符在 rpy2 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!