python code:
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.
In R command terminal, "rCommand" above works well.
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
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.
Your options might be:
run your code in a Linux VM (or container - MS has announced to be backing Docker)
submit a patch for rpy2
file a bug report on the bitbucket page for rpy2
hoping that this translates into a patch by someone
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). 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.