R shell vs. RStudio
NOTE: This blog post originally appeared on 12-Nov-2014 on the blog I kept when I was a postdoctoral researcher at the Ohio State University. I am reposting it here because several people have asked me about this very topic lately.
On several occasions I have wondered which criterion the R package rPython employs to set the version of Python it interacts with. According to the installation file of rPython, “[b]y default, the package will be installed using the Python version given by $ python –version”. That seemed to be only part of the story, I thought, since my Linux system has Python 2.7.8 set as the default Python version, yet installations of the package via RStudio resulted in Python 3.4.1 being utilized by rPython:
> library(rPython)
> python.exec("import sys; info=sys.version")
> python.get("info")
[1] "3.4.2 (default, Oct 8 2014, 13:44:52) \n[GCC 4.9.1 20140903 (prerelease)]"
What eluded me, however, was to evaluate if the command “python –version” would return Python 2.7.8, when run from RStudio, from where I usually install my R packages! Guess what: It does not.RStudio and the R shell invoke the bash shell differently, as evidenced by the following example:
In RStudio:
> system("python – version")
Python 3.4.2
In R shell:
> system("python – version")
Python 2.7.8
Hence, if I wish to have rPython interact with Python 2.7.8, I must install the package from the R shell.