{"id":217,"date":"2015-11-07T17:44:16","date_gmt":"2015-11-07T16:44:16","guid":{"rendered":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/?p=217"},"modified":"2015-11-07T17:48:17","modified_gmt":"2015-11-07T16:48:17","slug":"setting-the-default-python-version-in-r","status":"publish","type":"post","link":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/2015\/11\/07\/setting-the-default-python-version-in-r\/","title":{"rendered":"Setting the default Python version in R"},"content":{"rendered":"<p><strong>Easy if you know how.<\/strong><\/p>\n<p>We are living in a time of interconnectivity, and barely a day goes by when I don&#8217;t use the scripting language <em>R<\/em> in a more or less intricate pipeline. Often I have <em>R<\/em> call out to the interpreted programming language <em>Python<\/em> or the system shell to run a third-party executable (see the pipeline <a href=\"https:\/\/onlinelibrary.wiley.com\/doi\/10.1111\/1755-0998.12435\/abstract\" target=\"_blank\">P2C2M<\/a> as an example). In such situations it is essential that <em>R<\/em> and <em>Python<\/em> work together seamlessly.<\/p>\n<p>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 &#8220;default versions&#8221; is usually the way to go. But how do you set the default version of <em>Python<\/em> to be called by <em>R<\/em>?<\/p>\n<p>In Linux:<\/p>\n<div style=\"background-color: #ffebdb\">\n<p style=\"padding-left: 30px\"><code>echo 'alias python=python2.7' &gt;&gt; ~\/.bashrc<\/code><\/p>\n<\/div>\n<p>In MacOS (assuming that your <em>Python<\/em> version of choice resides in <em>\/usr\/local\/bin\/<\/em>):<\/p>\n<div style=\"background-color: #ffebdb\">\n<p style=\"padding-left: 30px\"><code>echo 'Sys.setenv(PATH = paste(\"\/usr\/local\/bin\", Sys.getenv(\"PATH\"), sep=\":\"))' &gt;&gt; \/path_to_R\/.Rprofile<\/code><\/p>\n<\/div>\n<p>Upon setting the default version as shown above, it is important that you re-compile the <em>R<\/em> package with which you call <em>Python<\/em> (e.g., <a href=\"https:\/\/rpython.r-forge.r-project.org\/\" target=\"_blank\">rPython<\/a>) from source and re-install it.<\/p>\n<p>Thanks go to my colleague Katie E. for sharing the above strategy necessary under MacOS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Easy if you know how. We are living in a time of interconnectivity, and barely a day goes by when I don&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":2306,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-217","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/users\/2306"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":4,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"predecessor-version":[{"id":221,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/posts\/217\/revisions\/221"}],"wp:attachment":[{"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/gruenstaeudl\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}