rPython-win icon indicating copy to clipboard operation
rPython-win copied to clipboard

Calling/Running python module in R

Open pmkruyen opened this issue 8 years ago • 2 comments

I installed rPython on my Windows 10 computer. The library seems to work fine. Thanks! As I am new to Python I could use some help running a python module in R. I tried various search strings on Google, but I could not find the answer. Hopefully, you could help me.

The problem is as follows. I installed the kpss module by jejansse. In python, the stem function works well, called by [kpss.stem(t) for t in "Alle eendjes zwemmen in het water".split()]).

Next, I managed to install rPython and loaded the required module using the function python.load("C:/Python27/Lib/kpss.py") . However, I do not know how to call the kpss.stem function. I played around with the assign and call functions, but these functions do not seem to work.

Your help is very much appreciated.

pmkruyen avatar Jul 06 '16 19:07 pmkruyen

Reading the rPython documentations carefully and with some trail and error, I found the solution myself.

In R:

python.exec( "import kpss" )
t<-c("eendjes")
python.call( "kpss.stem", t)
[1] "eend"

What does not work yet is the "for loop", When a string consisting of several words is used, the for loop is ignored and only the last word is stemmed.

Best, Peter

pmkruyen avatar Jul 07 '16 15:07 pmkruyen

python.exec('import pandas as pd') python.exec('print(pd.version)')

results nothing. I use rPython_0.0-6 RJSONIO_1.3-0 and Python 3.6.4.

Your help is very much appreciated.

andrejastojic avatar Mar 08 '18 17:03 andrejastojic