Installing Dependencies in RStudio

Installing Packages in RStudio: Pip, CRAN, and Tlmgr

In an RStudio environment, you may need to install packages from different sources, including CRAN (Comprehensive R Archive Network) for R packages, pip for Python packages, and Tlmgr for TeX packages. Below are the steps for installing packages from each of these sources.


Installing R Packages from CRAN

CRAN is the primary repository for R packages. To install an R package from CRAN, follow these steps:

  1. Open RStudio.

  2. Install a package using the install.packages() function. For example, to install the ggplot2 package, run:

    install.packages("ggplot2")
  3. Load the package into your R session with the library() function:

    library(ggplot2)

You can also use the RStudio interface:

  1. Go to the Tools menu.
  2. Select Install Packages.
  3. In the dialog box, enter the name of the package and click Install.

Installing R Packages from Source with Remotes

Sometimes, you might want to install the latest development version of a package directly from its source repository. The remotes package facilitates this.

  1. Install the remotes package (if not already installed):

    install.packages("remotes")
  2. Install a package from GitHub using remotes::install_github(). For example, to install the development version of ggplot2:

    remotes::install_github("tidyverse/ggplot2")
  3. Load the package into your R session:

    library(ggplot2)

You can also install packages from other version control platforms, such as GitLab and Bitbucket, by using the corresponding function from the remotes package, such as remotes::install_gitlab() or remotes::install_bitbucket().

Installing Archived CRAN packages

rgdal and rgeos have been archived from CRAN and need to be installed via the CRAN archives from source. Below are examples of the last archived versions of rgdal and rgeos.

remotes::install_url("https://cran.r-project.org/src/contrib/Archive/rgdal/rgdal_1.6-7.tar.gz", type="source")
remotes::install_url("https://cran.r-project.org/src/contrib/Archive/rgeos/rgeos_0.6-4.tar.gz", type="source")

Installing Python Packages with Pip

If you need to use Python packages within RStudio, you can install them using pip. Ensure you have Python and pip installed on your system.

  1. Open RStudio.

  2. Open the Terminal within RStudio:

    • Go to Tools > Terminal > New Terminal.
  3. Install a package using pip. For example, to install the numpy package, run:

pip install numpy

To use Python within R, the reticulate package is already installed in all sidecars:

  1. Load the reticulate package:
library(reticulate)
  1. Use Python within R:
np \<- import("numpy") np$array(c(1, 2, 3))

Installing TeX Packages with TinyTeX

In every sidecar, we provide a system installation of TeXLive with a set of common Latex Packages already installed. TinyTeX is a lightweight, portable, cross-platform, and easy-to-maintain LaTeX distribution. It integrates well with R and RStudio, making it convenient for managing LaTeX packages within your R environment.

Steps to Install Packages with TinyTeX

  1. Install the TinyTeX R Package (if not already installed):
install.packages("tinytex")
  • Note: A system installation of TeXLive is provided in all sidecars which tinytex will use as the base dependency. All installed packages through tinytex will be installed in your user directory under ~/.texlive[YYYY].
  1. Install a TeX Package Using TinyTeX:

To install a LaTeX package (e.g., amsmath), use:

tinytex::tlmgr_install("amsmath")
  • Replace "amsmath" with the name of the package you wish to install.
  1. Verify Installed Packages:

To list all installed LaTeX packages installed in your sidecar:

 tinytex::tl_pkgs()
  1. Compile Your R Markdown Document:
  • Create a new R Markdown document.
  • Knit it to PDF using rmarkdown or knitr.
  • TinyTeX will automatically use the packages installed in your user directory.

Installing TeX Packages with tlmgr

TeX Live Manager (tlmgr) is used to manage TeX Live packages, which are required for compiling LaTeX documents.

  1. TeX Live is installed on all sidecars. No need to install it yourself.

  2. Open the Terminal within RStudio:

    • Go to Tools > Terminal > New Terminal.
  3. Install a TeX package using Tlmgr. For example, to install the amsmath package, run:

    tlmgr install amsmath

If you require any LaTeX packages to be installed on your sidecar which require elevated permissions to install, please contact our support team for assistance.