[R] Loading multiple packages with install.packages()...
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Mon Sep 23 18:56:20 CEST 2024
"If you can get a vector with all the package names (I do not know how
to do this)..."
See ?available.packages
grep-ing the rownames of the available.packages() result appropriately
should give you a vector of the desired package names to install,
which can then be given to install.packages.
... Untested, so no guarantees.
Cheers,
Bert
On Mon, Sep 23, 2024 at 9:46 AM Ebert,Timothy Aaron <tebert using ufl.edu> 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-bounces using r-project.org> On Behalf Of Brian Lunergan
> Sent: Monday, September 23, 2024 12:35 PM
> To: r-help using r-project.org
> Subject: [R] Loading multiple packages with install.packages()...
>
> [External Email]
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
>
> 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...
> - --
> Brian Lunergan
> Russell, Ontario
> Canada
>
> -----BEGIN PGP SIGNATURE-----
>
> iQEzBAEBCgAdFiEETYnejayhh3NYXwphdgjwxcHhY5wFAmbxmNIACgkQdgjwxcHh
> Y5wR9wf7BDbw9feBoJ/F6y3vHCNxuksaDJn263ur9HKFgJYwHLqjD6yRqzvhf9IG
> N7G4LCmzjUk5NyjmKEGLCUCwGHYCxq6J0kKoWdwXczQzfxLDSBs2ePTcAhmaHmf4
> 60dZO7na9f6DXOqW2QQzb3A6P+dSUAHdhn1mP9RctjUq9pX1nrq+JUTAke/HsD/N
> mV6FkQX0HMgZZR3KTkORePy2q+Ejui+Ct1iS0sCpSLsOJ9X4U20GlimdvD8JY00M
> JWMPUgmu4nk9qebchqiegCydBMEemYT7FboS+B9fzGV7gHHojHYAppoQvPi5yjDy
> XfR+4SqRzBlLNHxUbhepwEmUAfeIQw==
> =JX0e
> -----END PGP SIGNATURE-----
>
> ______________________________________________
> R-help using 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 using 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.
More information about the R-help
mailing list