Using R language with Anaconda#
With Anaconda (or Miniconda), you can install the R programming language and over 6,000 commonly used R packages for data science. You can also create and share your own custom R packages.
Note
When using conda to install R packages, add r-
before the regular package name. For instance, to install rbokeh, use conda install r-rbokeh
. To install rJava, use conda install r-rjava
.
The R Essentials bundle contains approximately 200 of the most popular R packages for data science, including the IRKernel, dplyr, shiny, ggplot2, tidyr, caret, and nnet.
The version of the R interpreter installed into your R environments is based on the version of the r-base
package.
Note
Run the commands in the following sections in Anaconda Prompt (Terminal on macOS/Linux).
Updating R packages#
Caution
Exercise caution when using conda to update RStudio or other R packages to their latest versions. This might break your conda RStudio environment.
Update all of the packages and their dependencies by running the following command:
conda update r-caret
If a new version of a package is available in the R channel, update specific packages by running the following command:
conda update
Creating and sharing custom R bundles#
Creating and sharing custom R bundles is similar to creating and sharing conda packages. In the following example, we will create a simple custom R bundle metapackage named “Custom-R-Bundle”.
Create the metapackage “Custom-R-Bundle” that contains several popular programs and their dependencies by running the following command:
conda metapackage custom-r-bundle 0.1.0 --dependencies r-irkernel jupyter r-ggplot2 r-dplyr --summary "Custom-R-Bundle"
Upload the new metapackage to your channel on anaconda.org by running the following commands:
conda install anaconda-client anaconda login anaconda upload custom-r-bundle-0.1.0-0.tar.bz2
Anyone can now access your custom R bundle from any computer by running the following command:
# Replace <USERNAME> with your anaconda.org username
conda install -c <USERNAME> custom-r-bundle
Creating an environment with R#
Create a new conda environment with all the
r-essentials
conda packages built from CRAN by running the following command:conda create -n r_env r-essentials r-base
Activate the environment by running the following command:
conda activate r_env
List the packages in the environment by running the following command:
conda list
The list shows that the package r-base
is installed and r-
is listed in the build string of the other R packages in the environment.
Creating a new environment with R#
When creating a new environment, you can use R by explicitly including r-base
in your list of packages:
# Replace <ENV_NAME> with a name for your R environment conda create -n <ENV_NAME> r-base r-essentials conda activate <ENV_NAME>
Uninstalling R Essentials#
Uninstall the R Essentials package by running the following command:
# Replace <ENV_NAME> with the name of the R environment
conda activate <ENV_NAME>
conda remove r-essentials
Note
This removes only R Essentials and disables R language support. Other R language packages are not removed.
Resources#
Hundreds of R Language packages are available for use with Anaconda with several ways to get them.