1. Open Anaconda
  2.  Navigate to the Home tab within Anaconda
  3. Click the INSTALL button on the R-Studio card
  4. Anaconda will begin processing the install.
  5. 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.
  6. 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.
  7.  Click on the Play arrow of the desired environment and open a terminnal.
  8. From the terminal, install the needed Python packages using the pip installer:

    pip install keras
    pip install tensorflow


  9. 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.


  10. Close the command window.
  11. Navigate back to Anaconda Home
  12. 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.
  13.  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)