Read this post. And this one.
I would like to load packages in a oner and supress suppressPackageStartupMessages
at the same time.
The answer in the first link uses lapply:
packages <- c("tidyverse", "qdap", "stringr", "stringi", "textstem", "foreach", "caret", "xgboost", "quanteda")
lapply(packages, require, character.only = T)
This returns an unsightly list to the console:
[[1]]
[1] TRUE
[[2]]
[1] TRUE
[[3]]
[1] TRUE
[[4]]
[1] TRUE
Plus, I would like to also get rid of those messages that are sent to the console on load e.g.
> library(tidyverse)
Loading tidyverse: ggplot2
Loading tidyverse: dplyr
Conflicts with tidy packages --------------------------------------------------------------------
accumulate(): purrr, foreach
filter(): dplyr, stats
lag(): dplyr, stats
when(): purrr, foreach
Is there a clever, short way to both load a vector of packages AND suppressPackageStartupMessages?
You can install multiple packages by passing a vector of package names to the function, for example, install. packages(c("dplyr", "stringr")) . That function will install the requested packages, along with any of their non-optional dependencies.
suppressPackageStartupMessages() method in R language can be used to disable messages displayed upon loading a package in R. This method is used to suppress package startup messages. The package should be pre-installed in R, otherwise, a warning is displayed upon function call.
Once the package is installed, you must load the package and only after it has been loaded you can use all the functions and datasets it contains. To load a package, run library(name_of_package) (this time "" around the name of the package are optional, but can still be used if you wish).
One option would be
pacman::p_load(packages)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With