Home
Automatic Initialization on Windows
The following explains how to setup an .Renviron and .Rprofile file at Windows with a special focus on PythonInR, a general documentation can be found here
Where is my HOME Folder?
The home directory is normally set to C:\Users\username\Documents and can be obtained by typing
Sys.getenv("R_USER")into the R terminal. For more information see R for Windows FAQ - Question 2.14.
Set Persistent Environment Variables
To set persistent environment variables on Windows the file .Renviron can be utilized.
Just create a file with the name .Renviron in your home folder.
NOTE: Renaming a existing file to .Renviron didn't work for me since Windows complained that I should enter a file name. But saving a file from a text editor as .Renviron did work.
If your python.exe file is located at C:/Python27/python.exe you should put the following into your .Renviron file.
PYTHON_EXE=C:/Python27/python.exe
Or for those who prefer to not leave their R terminal.
envFile <- file.path(Sys.getenv("R_USER"), ".Renviron")
x <- if (file.exists(envFile)) readLines(envFile) else character()
x <- unique(c(x, 'PYTHON_EXE=C:/Python27/python.exe'))
writeLines(x, envFile)Setup .Rprofile
.Rprofile can be used to execute R code at the startup. Therefore it can also be used to set environment variables. Just put
Sys.setenv(PYTHON_EXE="C:/Python27/python.exe")into your .Rprofile file to get the same effect as with .Renviron. More information can be found here.