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.4.3/library   1.4-8     <NA>
#> ade4           ade4 C:/Program Files/R/R-4.4.3/library  1.7-23     <NA>
#> ADGofTest ADGofTest C:/Program Files/R/R-4.4.3/library     0.3     <NA>
#> admisc       admisc C:/Program Files/R/R-4.4.3/library    0.37     <NA>
#> AER             AER C:/Program Files/R/R-4.4.3/library  1.2-14     <NA>
#> afex           afex C:/Program Files/R/R-4.4.3/library   1.4-1     <NA>
#>                                                                                          Depends
#> abind                                                                               R (>= 1.5.0)
#> ade4                                                                                R (>= 3.5.0)
#> ADGofTest                                                                                   <NA>
#> 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)
#>                                                                                   Imports
#> abind                                                                      methods, utils
#> ade4                  graphics, grDevices, methods, stats, utils, MASS, pixmap, sp,\nRcpp
#> ADGofTest                                                                            <NA>
#> admisc                                                                            methods
#> AER                                                             stats, Formula (>= 0.2-0)
#> afex      pbkrtest (>= 0.4-1), lmerTest (>= 3.0-0), car, reshape2,\nstats, methods, utils
#>                     LinkingTo
#> abind                    <NA>
#> ade4      Rcpp, RcppArmadillo
#> ADGofTest                <NA>
#> admisc                   <NA>
#> AER                      <NA>
#> afex                     <NA>
#>                                                                                                                                                                                                                                                                                                                                                                                                  Suggests
#> abind                                                                                                                                                                                                                                                                                                                                                                                                <NA>
#> ade4                                                                                                                                                                                                                      ade4TkGUI, adegraphics, adephylo, adespatial, ape, CircStats,\ndeldir, lattice, spdep, splancs, waveslim, progress, foreach,\nparallel, doParallel, iterators, knitr, rmarkdown
#> ADGofTest                                                                                                                                                                                                                                                                                                                                                                                            <NA>
#> 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
#>           Enhances            License License_is_FOSS License_restricts_use
#> abind         <NA> MIT + file LICENSE            <NA>                  <NA>
#> ade4          <NA>         GPL (>= 2)            <NA>                  <NA>
#> ADGofTest     <NA>                GPL            <NA>                  <NA>
#> admisc        <NA>         GPL (>= 3)            <NA>                  <NA>
#> AER           <NA>      GPL-2 | GPL-3            <NA>                  <NA>
#> afex          <NA>         GPL (>= 2)            <NA>                  <NA>
#>           OS_type MD5sum NeedsCompilation Built
#> abind        <NA>   <NA>               no 4.4.1
#> ade4         <NA>   <NA>              yes 4.4.3
#> ADGofTest    <NA>   <NA>             <NA> 4.2.0
#> admisc       <NA>   <NA>              yes 4.4.3
#> AER          <NA>   <NA>               no 4.4.3
#> afex         <NA>   <NA>               no 4.4.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))