list packages installed from GitHub repository with their URL

Viewed 54

I was trying to install Git on Windows 11 which gives me troubles with RStudio (no git tab despite projects set up for version control). I want to try to reinstall Rstudio but I do not want to lose all the packages I've installed over the years.

I saved a list of my installed packages that I will then use to reinstall packages.

library(tidyverse)
ip = as.data.frame(installed.packages()[,])
list_packages <- ip %>% select(., Package, LibPath, Version, Built)
save(list_packages, file = "save_list_packages.RData")

It should work for CRAN packages but not for GitHub packages. Is there a way to list which packages are coming from GitHub along with their repo URLs? I tried to locate a package in GitHub from its name but it is hard to find as repos can have the same name (i.e. identified by their URL that includes username and repo name).

How do you do it in practise? Do you keep a script with all the GitHub package installations?

1 Answers

I suggest the function github_update() from the dtupdate package:

library(dtupdate)
list_gh <- github_update(auto.install = F)
#> Warning in read.dcf(url_con, fields = "Version"): cannot open URL 'https://
#> raw.githubusercontent.com/achetverikov/apastats/master/DESCRIPTION': HTTP status
#> was '404 Not Found'
#> Warning in read.dcf(url_con, fields = "Version"): cannot open URL 'https://
#> raw.githubusercontent.com/florianhartig/BayesianTools/master/DESCRIPTION': HTTP
#> status was '404 Not Found'
#> Warning in read.dcf(url_con, fields = "Version"): cannot open URL 'https://
#> raw.githubusercontent.com/jorvlan/raincloudplots/master/DESCRIPTION': HTTP
#> status was '404 Not Found'
head(list_gh)
#>         package       date version gh_version *
#> 1       adventr 2021-08-10  0.1.10     0.1.10  
#> 2        anicon 2021-11-20   0.1.0      0.1.0  
#> 3      apastats 2022-03-24     0.3       <NA>  
#> 4 BayesianTools 2021-06-14   0.1.7       <NA>  
#> 5        bbplot 2020-06-09     0.2        0.2  
#> 6     beautifyR 2022-01-10   0.3.1      0.3.2 *
#>                                         source
#> 1       Github (profandyfield/adventr@2d894ca)
#> 2            Github (emitanaka/anicon@0b756df)
#> 3       Github (achetverikov/apastats@448bb21)
#> 4 Github (florianhartig/BayesianTools@3f306aa)
#> 5                  Github (bbc/bbplot@82af595)
#> 6              Github (mwip/beautifyR@331a2cc)

The column source will show the user and the repo...

And, by the way... if you want to install all github packages from the respective user/repo:

library(rex)
#extract only the "user/name" from the list_gh$source column
matches <- re_matches(list_gh$source,
                      rex(
                        "(",
                        capture(name = "text", except_any_of(")")),
                        "@"),
                      global = TRUE)
#add it as a column to the list_gh data frame (you do not really need this step) but to keep it more organized...
list_gh$user_repo <- matches |> bind_rows()

#install all github packages using pacman
pacman::p_install_gh(list_gh$user_repo)

Created on 2022-08-11 by the reprex package (v2.0.1)

Related