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