Michael Grünstäudl (Gruenstaeudl), PhD

Postdoctoral Researcher at the Freie Universität Berlin

Setting the default Python version in R

Easy if you know how.

We are living in a time of interconnectivity, and barely a day goes by when I don’t use the scripting language R in a more or less intricate pipeline. Often I have R call out to the interpreted programming language Python or the system shell to run a third-party executable (see the pipeline P2C2M as an example). In such situations it is essential that R and Python work together seamlessly.

To ensure inter-operability, it is important for each scripting language to call the correct version of the other. To do that, the setting of “default versions” is usually the way to go. But how do you set the default version of Python to be called by R?

In Linux:

echo 'alias python=python2.7' >> ~/.bashrc

In MacOS (assuming that your Python version of choice resides in /usr/local/bin/):

echo 'Sys.setenv(PATH = paste("/usr/local/bin", Sys.getenv("PATH"), sep=":"))' >> /path_to_R/.Rprofile

Upon setting the default version as shown above, it is important that you re-compile the R package with which you call Python (e.g., rPython) from source and re-install it.

Thanks go to my colleague Katie E. for sharing the above strategy necessary under MacOS.

Der Beitrag wurde am Saturday, den 7. November 2015 um 17:44 Uhr von Michael Grünstäudl veröffentlicht und wurde unter Allgemein abgelegt. Sie können die Kommentare zu diesem Eintrag durch den RSS 2.0 Feed verfolgen. Sie können einen Kommentar schreiben, oder einen Trackback auf Ihrer Seite einrichten.

Leave a Reply

Hinweis / Hint
Das Captcha kann Kleinbuchstaben, Ziffern und die Sonderzeichzeichen »?!#%&« enthalten.
The captcha could contain lower case, numeric characters and special characters as »!#%&«.