- R: https://cran.r-project.org/
- Python 2.7, 3.4, 3.5 or 3.6: https://www.continuum.io/downloads
- rpy2 pip package (Windows only): http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2
- Install R
- Install Anaconda
- Edit Environment Variables (Control Panel -> System -> Advanced system settings -> Environment Variables)
- Select Path -> Edit and add R installation path (default location is "C:\Program Files\R\R-3.4.1\bin\x64") to Path variable and press OK
- Select New and add R_HOME in variable name and base R directory (default is "C:\Program Files\R\R-3.4.1") to variable value
- Select New and add R_USER in variable name and your Windows user name (You can check this by typing echo %username% in command window) to variable value
- Open Windows command window as admin (or launch terminal on linux as root) and enter the following commands.
*On Linux just use the command pip install rpy2, environment variables should already be set otherwise you can set them by using export command. pip install rpy2-2.8.6-cp35-cp35m-win_amd64.whl
- After successful install you can run the following commands to test if you can run R code in python
You should be able to run R commands from Python after this step. See https://rpy2.readthedocs.io/en/version_2.8.x/index.html for further help.
C:\> python >>> import rpy2 >>> print(rpy2.__version__) 2.8.6 >>> from rpy2.rinterface import R_VERSION_BUILD >>> print(R_VERSION_BUILD) ('3', '3.3', '', 72310) >>> import rpy2.robjects as robjects >>> pi = robjects.r['pi'] >>> pi 3.141592653589793