简体   繁体   English

rpy2:韩文字符不能用于rpy2

[英]rpy2 : Korean characters are not working on rpy2

python code: 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)

Korean characters makes the python.exe killed. 韩文字符使python.exe被杀死。

In R command terminal, "rCommand" above works well. 在R命令终端中,上面的“rCommand”运行良好。

I couldn't find any solution. 我找不到任何解决方案。

Any help would be appreciated. 任何帮助,将不胜感激。

my env: window 7 x64, python 2.7.8 x64, rpy2 2.5.4, R 3.1.2 我的环境:窗口7 x64,python 2.7.8 x64,rpy2 2.5.4,R 3.1.2

At the time of writing, there is unfortunately no official support of rpy2 for windows. 在撰写本文时,遗憾的是没有官方支持rpy2 for windows。 The code snippet you are providing is working fine on Linux. 您提供的代码片段在Linux上正常运行。

Your options might be: 您的选择可能是:

  • run your code in a Linux VM (or container - MS has announced to be backing Docker) 在Linux VM(或容器 - MS已宣布支持Docker)中运行您的代码

  • submit a patch for rpy2 提交rpy2补丁

  • file a bug report on the bitbucket page for rpy2 hoping that this translates into a patch by someone rpy2的bitbucket页面上提交错误报告,希望这可以转换为某人的补丁

Edit: 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). 编辑:评论表明,使用编码帮助Python 2.7可能有所帮助(没有承诺 - 一切都在Linux上运行,所以这可能是特定于Windows的)。 A string can be explicitly specified to be in unicode with (note the prefix u before ''' ): 可以将字符串显式指定为unicode(注意'''之前的前缀u ):

rCommand=u'''
    gender <- c("남자", "남자", "남자", "여자", "여자", "여자", "여자", "여자")
    age    <- c(23, 25, 27, 29, 31, 33, 35, 37)
    outdf <- data.frame(gender, age)
'''
robjects.r(rCommand)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM