Continuing with this approach:

a1 <- available.packages()
packages <- grep("^rcmdrplugin", rownames(a1), ignore.case = TRUE, value = TRUE)
missing_pkgs <- setdiff(packages, rownames(installed.packages()))
install.packages(missing_pkgs, dependencies = TRUE)

The pacman package also handles some of these "install only if not already installed" tasks.

On 2024-09-23 12:40 p.m., Ebert,Timothy Aaron wrote:
If you can get a vector with all the package names (I do not know how to do 
this) then you could do something like this;
# Function to check and install missing packages
install_if_missing <- function(pkg) {
   if (!require(pkg, character.only = TRUE)) {
     install.packages(pkg, dependencies = TRUE)
   }
   library(pkg, character.only = TRUE)
}
# List of required packages.
packages <- c("emmeans", "multcomp", "sandwich", "multcompView", "ggplot2", "stringr", "dplyr", 
"openxlsx", "tidyr")
# Check and install each package
lapply(packages, install_if_missing)


Regards,
Tim
-----Original Message-----
From: R-help <r-help-boun...@r-project.org> On Behalf Of Brian Lunergan
Sent: Monday, September 23, 2024 12:35 PM
To: r-help@r-project.org
Subject: [R] Loading multiple packages with install.packages()...

[External Email]

Hi folks:

Curious question. I've added Rcmdr to my setup (R 4.4.1). I would like to add 
all of the plugins. Is there a way to get install.packages() to gather up 
everything starting 'rcmdrplugin', or do I have to list each package 
individually between the brackets?? 😕️

Regards...

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
E-mail is sent at my convenience; I don't expect replies outside of
working hours.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to