- Open Anaconda
- Navigate to the Home tab within Anaconda
- Click the INSTALL button on the R-Studio card
- Anaconda will begin processing the install.
- After a while, Anaconda will prompt asking you to add R to an existing, or create a new environment. When prompted, type a name of your choosing for a new environment.
- Once the Installation and Environment setup completes, the next steps will be to install the needed Python Packages. In order to do so, navigate to the Environments tab in Anaconda.
- Click on the Play arrow of the desired environment and open a terminnal.
From the terminal, install the needed Python packages using the pip installer:
pip install keras pip install tensorflow
Before proceeding, determine the paths to both Python and the environment by running this command:
env | findstr "CONDA_PREFIX"
The paths are usually in one of two places:
C:\conda\env\[EnvironmentName]
or:
C:\Users\[UserName]\Anaconda3\env\[EnvironmentName]
Note the path down, you will need it to create the paths to python, environment and the conda environment name to be used within your R code.- Close the command window.
- Navigate back to Anaconda Home
- Launch R Studio from within the desired Conda environment by choosing the desired environment from the Applications on drop down menu and then clicking Launch.
- In your R program, run the following:
install.packages('reticulate') install.packages('kerasR') install.packages('keras') install.packages('tensorflow') #Replace the [Environment_Name] with the actual environment name without the brackets. Note: the full path may be different if Anaconda was only installed within a single user's account. PathToPy = "C:/Conda/envs/[Environment_Name]/python.exe" PathToEnv = "C:/Conda/envs/[Environment_Name]" PathToCondaEnv = "[Environment_Name]" library(tensorflow) library(reticulate) reticulate::use_python(PathToPy) reticulate::use_virtualenv(PathToEnv) reticulate::use_condaenv(PathToCondaEnv) library(keras) install_keras() library(kerasR) kerasR::keras_init() Sys.setenv(KERAS_PYTHON = PathToPy) Sys.setenv(TENSORFLOW_PYTHON= PathToPy)