Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Package installation is persistent, but you cannot know in advance which node of the cluster will launch your job.

Thus do not assume any package is don't assume packages are already installed and always use:

Code Block
pkgs <-
  c("data.table", "dplyr", "ggplot2")
for (pkg in pkgs) {
  if (!requirelength(find.package(pkg, character.onlyquiet = TRUE))) { 
    install.packages(pkg, repos = "https://cloud.r-project.org/")
  
 library(pkg, character.only = TRUE)
  } 
}

If your package has a system dependency, you can install it like this: 

Code Block
if (!require("mongolite")) {
  # Install system dependencies
  # system("sudo apt-get install -y libssl-dev libsasl2-dev")
  install.packages("mongolite", repos = "https://cloud.r-project.org/")
  library("mongolite")
}data.table)
library(dplyr)
library(ggplot2)