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
installed.packages(fields ="URL")
. In the future you should keep a list of packages that you install from github somewhere else to make it easier to reinstall them. Maybe consider something like renv to manage package dependencies rather than just trying to copy over entire package libraries. – SwithinR
like! Instead of coping entire package libraries, what is your approach, do you only install packages as you need them after an update? Surely you have a core number of packages you always need to install? – Accidenceinstalled.packages(fields ="URL")
to find the URLs given in the description files for your installed packages (on your old R). You can grep for "github" in the URL to see if they included the repo where the package came from. Note that many CRAN packages will still also include the github repo link in the URL, so just do this for packages that fail. I always start over with major R releases and install on demand. This helps me avoid reinstalling things I'll never use. I work on so many different machines that it better for me to manage packages at the project level, not system. – Swithinpak
should take care about installing either from CRAN or from GitHub in a single command. But still authors names are needed. – Chipman