4.11.4 Create a Conda Environment for R and Install R Packages

This topic shows how to create a Conda environment for R packages, with R-4.0.5 for OML4R compatibility, and install the forecast and ggplot2 packages.

Note:

You must be signed in as ADMIN user to create the Conda environment.

Note:

To avoid version conflicts, please do not install packages that are already included in OML4R. For a complete list of pre-installed packages and their versions, see About the OML4R Supporting Packages
To create a Conda environment named myrenv with R-4.0.5 for OML4R compatibility and install the packages forecast and ggplot2:
  1. Run the following command to create the environment for R by the name myrenv and also install the packages forecast and ggplot2:
    %conda
    
    create -n myrenv -c conda-forge --override-channels --strict-channel-priority r-base=4 r-forecast r-ggplot2
    In this example, we are using the conda-forge channel to install the R packages.
    In this command:
    • -n: This is the name of the environment. In this example, it is myrenv.
    • -c: This is the channel name. In this example, it is conda-forge.
    • --override-channels: This argument ensures that the system does not search default, and requires a channel to be mentioned.
    • --strict-channel-priority: This argument ensures that packages in lower priority channels are not considered if a package with the same name appears in a higher priority channel. In this example, the priority is given to R-4.0.5, forecast, and ggplot2.
    The command returns the following:

    Figure 4-52 Command to create Conda environment for R and install R Packages


    Command to create Conda environment for R and install R Packages

  2. You may now verify the Conda environment for R that you just created. Run the following command in a %conda paragraph to view the list of environments.
    env list
    Note that the myrenv environment is now listed along with the mypyenv in the output.

    Figure 4-53 myrenv environment created and listed


    myrenv environment created and listed

    Note that the asterisk (*) is against the mypyenv, indicating that this environment is active currently.