When you are doing an R
update, what is the best approach to re-installing and updating all packages that were already installed on your previous R
version when some of your packages are on CRAN
but the rest are on github
(or other sources)?
In the past, I've followed this approach:
Open old version of R
(e.g. R 3.6
) and make a copy of all installed packages:
installed <- as.data.frame(installed.packages())
#save a copy
write.csv(installed, 'previously_installed.csv')
Then install and open new version of R
(e.g. R 4.1
), read in the old package names and install (from default: CRAN
):
previously_installed <- read.csv('previously_installed.csv')
package_list <- as.character(previously_installed$Package)
package_list
install.lib <- package_list[!package_list %in% installed.packages()]
for(lib in install.lib) install.packages(lib, dependencies = TRUE)
This works really well but will only install packages that are on CRAN
so all packages that are only on github
won't be installed. Is there a way to automatically install these packages from github
?
You could work out which packages weren't installed (e.g. remaining github
packages):
git_packages_not_installed <- install.lib[!install.lib %in% installed.packages()]
I think you need to know the authors name to install all github
packages though so I'm not sure how to automate this (e.g. devtools::install_github("DeveloperName/PackageName")
. I know you can supply two repository options but I'm not sure this helps or see here.
What is best practice in this situation?
thanks