Skip to contents

This function checks if a specified package is installed. If the package is not installed, it installs it from CRAN, then loads it into the R session.

Usage

load_or_install_cran(pkg)

Arguments

pkg

A character string specifying the name of the package to be loaded or installed.

Value

This function does not return a value. It is called for its side effect of loading or installing the package.

Details

The function first checks if the package is available in the current session using requireNamespace. If the package is not installed, it installs it using install.packages and then loads it using library.

Examples

if (FALSE) { # \dontrun{
load_or_install_cran("ggplot2")
load_or_install_cran("dplyr")
} # }