You can install R packages into your Jupyter environment using our Conda and CRAN package manager classes. The Conda class wraps the conda
command with additional configurations to work properly in our environment. The CRAN class wraps the R package install functions to achieve the same results. Both classes add authentication and endpoint configuration to get the requested packages without violating security protocols. They also automatically resolve dependencies, installing any packages required by the packages you requested.
Some newly installed packages don’t work properly until you restart the kernel.
We recommend that you create a notebook exclusively for installing packages and that you don’t start other notebooks until you're finished installing packages.
When you’re ready, restart the kernel: go to the Kernel menu and click Restart Kernel.
See the following sections for steps and examples.
The following sections show how to use our Conda class to install, list, remove, and purge R packages.
To begin, get an instance of our Conda class:
library(fbrir) conda = Conda$new()
Install a package (or a list of packages) by calling the conda.Install
function and passing in either a string with the package name (for a single package) or a list of comma-separated strings (for multiple packages). You can also specify the optional channel
argument to set a different Conda channel (the default is conda-forge
).
In Conda, most R package names begin with "r-".
The following example shows how to install a single package:
conda$Install("r-treemap") # Install a single package
The system response should look like this:
"[FORT] Installing conda: r-treemap , from: https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64" "Executing [conda install -p /home/jovyan/.fort/user_packages/conda -y --override-channels -c https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64 r-treemap]" "Collecting package metadata (current_repodata.json): ...working... done" "Solving environment: ...working... done" "" "# All requested packages already installed." "" "Done installing r-treemap"
The following example shows how to install multiple packages:
# installing multiple packages conda$Install(c("r-timetk", "r-timereg"))
The system response should look like this:
"[FORT] Installing conda: r-timetk , from: https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64" "Executing [conda install -p /home/jovyan/.fort/user_packages/conda -y --override-channels -c https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64 r-timetk]" "Collecting package metadata (current_repodata.json): ...working... done" "Solving environment: ...working... done" "" "## Package plan ##" "" " environment location: /home/jovyan/.fort/user_packages/conda" "" " added / updated specs:" " - r-timetk" "" "" "The following packages will be downloaded:" "" " package | build" " ---------------------------|-----------------" " r-future.apply-1.9.0 | r41hc72bb7e_0 165 KB https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge" " ------------------------------------------------------------" " Total: 165 KB" "" "The following NEW packages will be INSTALLED:" "" " r-anytime public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64::r-anytime-0.3.9-r41h03ef668_0" " r-askpass public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64::r-askpass-1.1-r41hcfec24a_2" " r-assertthat public/external-proxy/https://conda.anaconda.org/conda-forge/noarch::r-assertthat-0.2.1-r41hc72bb7e_2" ... # Some packages omitted from this output example for brevity " r-timedate public/external-proxy/https://conda.anaconda.org/conda-forge/noarch::r-timedate-3043.102-r41hc72bb7e_1002" " r-timetk public/external-proxy/https://conda.anaconda.org/conda-forge/noarch::r-timetk-2.8.0-r41hc72bb7e_0" " r-tseries public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64::r-tseries-0.10_50-r41h1463581_0" ... # Some packages omitted from this output example for brevity "" "" "Downloading and Extracting Packages" "\rr-future.apply-1.9.0 | 165 KB | | 0% \rr-future.apply-1.9.0 | 165 KB | 9 | 10% \rr-future.apply-1.9.0 | 165 KB | ########## | 100% " "Preparing transaction: ...working... done" "Verifying transaction: ...working... done" "Executing transaction: ...working... done" Warning message: “package ‘timetk’ was built under R version 4.1.3” "Done installing r-timetk" "[FORT] Installing conda: r-timereg , from: https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64" "Executing [conda install -p /home/jovyan/.fort/user_packages/conda -y --override-channels -c https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64 r-timereg]" "Collecting package metadata (current_repodata.json): ...working... done" "Solving environment: ...working... done" "" "## Package Plan ##" "" " environment location: /home/jovyan/.fort/user_packages/conda" "" " added / updated specs:" " - r-timereg" "" "" "The following NEW packages will be INSTALLED:" "" " r-timereg public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64::r-timereg-2.0.2-r41h0154571_0" "" "" "Preparing transaction: ...working... done" "Verifying transaction: ...working... done" "Executing transaction: ...working... done" Warning message: “package ‘timereg’ was built under R version 4.1.3” Loading required package: survival Warning message: “package ‘survival’ was built under R version 4.1.2” "Done installing r-timereg"
Use the conda$list
function to list installed packages. This list might include packages that you did not explicitly install.
The following example shows requesting the list of installed packages:
conda$List()
The system response should look like this (only a subset of columns are shown):
Uninstall packages by calling the conda$Remove
function. Just like the conda.Install
function, you can pass in a single string for a single package, or a comma-separated list of strings for a list of packages. Removing a package using Conda also removes dependent packages.
Only uninstall packages that you have installed.
Attempting to uninstall system-level packages can lead to unexpected errors. See Troubleshooting for recovery suggestions, if needed.
The following example shows how to uninstall a single package:
conda$Remove("r-timetk")
The system response should look like this:
"Removing conda package: r-timetk" "Executing [conda remove -p /home/jovyan/.fort/user_packages/conda -y --override-channels -c https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64 r-timetk]" "Collecting package metadata (repodata.json): ...working... done" "Solving environment: ...working... done" "" "## Package plan ##" "" " environment location: /home/jovyan/.fort/user_packages/conda" "" " removed specs:" " - r-timetk" "" "" "The following packages will be REMOVED:" "" " r-anytime-0.3.9-r41h03ef668_0" " r-askpass-1.1-r41hcfec24a_2" " r-assertthat-0.2.1-r41hc72bb7e_2" ... # Some packages omitted from this output example for brevity " r-timetk-2.8.0-r41hc72bb7e_0" ... # Some packages omitted from this output example for brevity "" "" "Preparing transaction: ...working... done" "Verifying transaction: ...working... done" "Executing transaction: ...working... done"
The following example shows how to uninstall multiple packages:
# uninstall multiple packages conda$Remove(c("r-treemap", "r-timereg"))
The system response should look like this:
"Removing conda package: r-treemap" "Executing [conda remove -p /home/jovyan/.fort/user_packages/conda -y --override-channels -c https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64 r-treemap]" "Collecting package metadata (repodata.json): ...working... done" "Solving environment: ...working... done" "" "## Package Plan ##" "" " environment location: /home/jovyan/.fort/user_packages/conda" "" " removed specs:" " - r-treemap" "" "" "The following packages will be REMOVED:" "" " gmp-6.2.1-h58526e2_0" " r-backports-1.4.1-r41hcfec24a_0" " r-base64enc-0.1_3-r41hcfec24a_1004" ... # Some packages omitted from this output example for brevity " r-treemap-2.4_3-r41hc72bb7e_0" ... # Some packages omitted from this output example for brevity "" "" "Preparing transaction: ...working... done" "Verifying transaction: ...working... done" "Executing transaction: ...working... done" "Removing conda package: r-timereg" "Executing [conda remove -p /home/jovyan/.fort/user_packages/conda -y --override-channels -c https://mesa-override-graph-api.test.fb-researchtool.com/public/external-proxy/https://conda.anaconda.org/conda-forge/linux-64 r-timereg]" "Collecting package metadata (repodata.json): ...working... done" "Solving environment: ...working... done" "" "## Package Plan ##" "" " environment location: /home/jovyan/.fort/user_packages/conda" "" " removed specs:" " - r-timereg" "" "" "The following packages will be REMOVED:" "" " _r-mutex-1.0.1-anacondar_1" " binutils_impl_linux-64-2.36.1-h193b22a_2" " binutils_linux-64-2.36-hf3e587d_9" ... # Some packages omitted from this output example for brevity " r-timereg-2.0.2-r41h0154571_0" ... # Some packages omitted from this output example for brevity "" "" "Preparing transaction: ...working... done" "Verifying transaction: ...working... done" "Executing transaction: ...working... done"
The conda$Purge
function allows you to start fresh with nothing installed from Conda. The following example removes every package that you installed, without removing any of the environment's default packages:
conda$Purge()
The system response should look like this:
"Executing [rm -rf /home/jovyan/.fort/user_packages/conda/*]"
The conda$List
function should show no results after using the conda$Purge
function.
The following sections show how to use our CRAN class to install, list, remove, and purge R packages.
To begin, get an instance of our CRAN class:
library(fbrir) cran = CRAN$new()
Install a package (or a list of packages) by calling the cran.InstallPackages
function and passing in either a string with the package name (for a single package) or a list of comma-separated strings (for multiple packages). You can also specify if you don't want the package dependencies to be installed by including the optional dependencies=FALSE
argument. By default, dependencies=TRUE
is set.
The following example shows how to install a single package:
cran$InstallPackages("abglasso") # Install a single package
The system response should look like this:
"Installing CRAN package(s): abglasso, from: https://cran.rstudio.com/" "Done installing abglasso"
The following example shows how to install multiple packages:
cran$InstallPackages(c("abctools", "abdiv")) #Install multiple packages
The system response should look like this:
"Installing CRAN package(s): abctools, from: https://cran.rstudio.com/" "Installing CRAN package(s): abdiv, from: https://cran.rstudio.com/" also installing the dependencies ‘permute’, ‘abc’, ‘abc.data’, ‘vegan’ Loading required package: abc Loading required package: abc.data Loading required package: nnet Loading required package: quantreg Loading required package: SparseM Attaching package: ‘SparseM’ The following object is masked from ‘package:base’: backsolve Loading required package: MASS Warning message: “package ‘MASS’ was built under R version 4.1.3” Loading required package: locfit locfit 1.5-9.5 2022-03-01 Loading required package: abind Loading required package: parallel Loading required package: plyr Loading required package: Hmisc Loading required package: lattice Loading required package: survival Attaching package: ‘survival’ The following object is masked from ‘package:quantreg’: untangle.specials Loading required package: Formula Loading required package: ggplot2 Attaching package: ‘Hmisc’ The following objects are masked from ‘package:plyr’: is.discrete, summarize The following object is masked from ‘package:quantreg’: latex The following objects are masked from ‘package:base’: format.pval, units ********************************************** abctools: A package with tools for ABC inference --- Written by Matt Nunes and Dennis Prangle--- Current package version: 1.1.3 ( 2018-07-17 ) ********************************************** abctools 1.1.3 loaded "Done installing abctools" "Done installing abdiv"
Use the cran$InstalledPackages
function to list installed packages.
The following example shows requesting the list of installed packages:
cran$InstalledPackages()
The system response should look like this (only a subset of columns are shown):
Uninstall packages by calling the cran$RemovePackages
function. Just like the cran$InstallPackages
function, you can pass in a single string for a single package, or a comma-separated list of strings for a list of packages.
Removing a package using CRAN does not automatically remove dependent packages.
Only uninstall packages that you have installed.
Attempting to uninstall system-level packages can lead to unexpected errors. See Troubleshooting for recovery suggestions, if needed.
The following example shows how to uninstall a single package:
cran$RemovePackages("abglasso") # Remove a single package
The system response should look like this:
"Removing CRAN package(s): abglasso"
The following example shows removing multiple packages:
cran$RemovePackages(c("abctools", "abdiv")) #Remove multiple packages
The system response should look like this:
"Removing CRAN package(s): abctools" "Removing CRAN package(s): abdiv"
The cran$PurgePackages
function allows you to start fresh with nothing installed from CRAN. The following example removes every package that you installed, without removing any of the environment's default packages:
cran$PurgePackages()
The system response should look like this:
"Executing [rm -rf /home/jovyan/.fort/user_packages/cran/*]"
The cran$InstalledPackages
function should show no results after using the cran$PurgePackages
function.
Installing packages carries with it some risk of installing or upgrading dependent packages that are incompatible with one another. If your environment becomes unstable as a result, we recommend the steps below.
When you purge your environment, you remove all of the packages that you installed, giving your environment a fresh start. Once you do this, restart the affected kernels and you should be back on track. Learn more about how to purge Conda packages or purge CRAN packages.
If purging your environment doesn’t solve the problem, it’s likely there's an error in one of the system libraries. Because all system-level changes are ephemeral, we recommend that you restart the environment as follows: