A.5 Install all necessary packages/libaries on your local machine

Get a list of packages you need to install from this book (or your local device)

installed <- as.data.frame(installed.packages())

head(installed)
#>         Package                            LibPath Version Priority
#> abind     abind C:/Program Files/R/R-4.2.3/library   1.4-5     <NA>
#> ade4       ade4 C:/Program Files/R/R-4.2.3/library  1.7-22     <NA>
#> admisc   admisc C:/Program Files/R/R-4.2.3/library    0.33     <NA>
#> AER         AER C:/Program Files/R/R-4.2.3/library  1.2-10     <NA>
#> afex       afex C:/Program Files/R/R-4.2.3/library   1.3-0     <NA>
#> agridat agridat C:/Program Files/R/R-4.2.3/library    1.21     <NA>
#>                                                                                        Depends
#> abind                                                                             R (>= 1.5.0)
#> ade4                                                                               R (>= 2.10)
#> admisc                                                                            R (>= 3.5.0)
#> AER     R (>= 3.0.0), car (>= 2.0-19), lmtest, sandwich (>= 2.4-0),\nsurvival (>= 2.37-5), zoo
#> afex                                                             R (>= 3.5.0), lme4 (>= 1.1-8)
#> agridat                                                                                   <NA>
#>                                                                                 Imports
#> abind                                                                    methods, utils
#> ade4                graphics, grDevices, methods, stats, utils, MASS, pixmap, sp,\nRcpp
#> admisc                                                                          methods
#> AER                                                           stats, Formula (>= 0.2-0)
#> afex    pbkrtest (>= 0.4-1), lmerTest (>= 3.0-0), car, reshape2,\nstats, methods, utils
#> agridat                                                                            <NA>
#>                   LinkingTo
#> abind                  <NA>
#> ade4    Rcpp, RcppArmadillo
#> admisc                 <NA>
#> AER                    <NA>
#> afex                   <NA>
#> agridat                <NA>
#>                                                                                                                                                                                                                                                                                                                                                                                                Suggests
#> abind                                                                                                                                                                                                                                                                                                                                                                                              <NA>
#> ade4                                                                                                                                                                                                                                                  ade4TkGUI, adegraphics, adephylo, ape, CircStats, deldir,\nlattice, spdep, splancs, waveslim, progress, foreach, parallel,\ndoParallel, iterators
#> admisc                                                                                                                                                                                                                                                                                                                                                                                     QCA (>= 3.7)
#> AER                                                                                                                                  boot, dynlm, effects, fGarch, forecast, foreign, ineq,\nKernSmooth, lattice, longmemo, MASS, mlogit, nlme, nnet, np,\nplm, pscl, quantreg, rgl, ROCR, rugarch, sampleSelection,\nscatterplot3d, strucchange, systemfit (>= 1.1-20), truncreg,\ntseries, urca, vars
#> afex    emmeans (>= 1.4), coin, xtable, parallel, plyr, optimx,\nnloptr, knitr, rmarkdown, R.rsp, lattice, latticeExtra,\nmultcomp, testthat, mlmRev, dplyr, tidyr, dfoptim, Matrix,\npsychTools, ggplot2, MEMSS, effects, carData, ggbeeswarm, nlme,\ncowplot, jtools, ggpubr, ggpol, MASS, glmmTMB, brms, rstanarm,\nstatmod, performance (>= 0.7.2), see (>= 0.6.4), ez,\nggResidpanel, grid, vdiffr
#> agridat                    AER, agricolae, betareg, broom, car, coin, corrgram, desplot,\ndplyr, effects, equivalence, emmeans, FrF2, gam, gge, ggplot2,\ngnm, gstat, HH, knitr, lattice, latticeExtra, lme4, lucid,\nmapproj, maps, MASS, MCMCglmm, metafor, mgcv, NADA, nlme,\nnullabor, ordinal, pbkrtest, pls, pscl, reshape2, rgdal,\nrmarkdown, qicharts, qtl, sp, SpATS, survival, vcd, testthat
#>         Enhances       License License_is_FOSS License_restricts_use OS_type
#> abind       <NA>   LGPL (>= 2)            <NA>                  <NA>    <NA>
#> ade4        <NA>    GPL (>= 2)            <NA>                  <NA>    <NA>
#> admisc      <NA>    GPL (>= 3)            <NA>                  <NA>    <NA>
#> AER         <NA> GPL-2 | GPL-3            <NA>                  <NA>    <NA>
#> afex        <NA>    GPL (>= 2)            <NA>                  <NA>    <NA>
#> agridat     <NA>  CC BY-SA 4.0            <NA>                  <NA>    <NA>
#>         MD5sum NeedsCompilation Built
#> abind     <NA>               no 4.2.0
#> ade4      <NA>              yes 4.2.3
#> admisc    <NA>              yes 4.2.3
#> AER       <NA>               no 4.2.3
#> afex      <NA>               no 4.2.3
#> agridat   <NA>               no 4.2.3

write.csv(installed, file.path(getwd(),'installed.csv'))

After having the installed.csv file on your new or local machine, you can just install the list of packages

# import the list of packages
installed <- read.csv('installed.csv')

# get the list of packages that you have on your device
baseR <- as.data.frame(installed.packages())

# install only those that you don't have
install.packages(setdiff(installed, baseR))