KWB-R/pkgmeta

Add functions for package reverse dependency check

Opened this issue · 1 comments

As described in http://www.tinyverse.org/, R package dependencies should be as lean as possible. To check wether this is the case for our KWB-R packages the follwing functions should be added to pkgmeta and added to a vignette for automating this analysis (at least for the public R packages).

get_recursive_pkg_dependencies <-
  function(pkgs,
           library_path = .libPaths(),
           dbg = TRUE) {
    pkgs_installed <-
      pkgs[pkgs %in% rownames(installed.packages(lib.loc = library_path))]
    
    setNames(lapply(pkgs_installed, function(pkg) {
      kwb.utils::catAndRun(
        sprintf("Getting recursive dependencies for '%s'", pkg),
        expr = {
          packrat:::recursivePackageDependencies(pkg,
                                                 lib.loc = library_path)
        },
        dbg = dbg
      )
    }),
    nm = pkgs_installed)
    
  }


get_pkg_dependencies <-
  function(pkgs,
           library_path = .libPaths(),
           dbg = TRUE) {
    pkgs_installed <-
      pkgs[pkgs %in% rownames(installed.packages(lib.loc = library_path))]
    
    setNames(lapply(pkgs_installed, function(pkg) {
      kwb.utils::catAndRun(
        sprintf("Getting dependencies for '%s'", pkg),
        expr = {
          packrat:::getPackageDependencies(pkg, lib.loc = library_path)
        },
        dbg = dbg
      )
    }),
    nm = pkgs_installed)
    
  }



###############################################################################
### Define Function for Installing KWB-R GitHub Packages
###############################################################################

install_kwb_github_packages <- function(pkgs_kwb,
                                        dependencies = TRUE,
                                        ...) {
  pkgs_kwb_github <- sprintf("KWB-R/%s", pkgs_kwb)
  
  sapply(
    pkgs_kwb_github,
    FUN = function(gh_repo) {
      try(remotes::install_github(repo = gh_repo,
                                  dependencies = dependencies,
                                  ...))
    }
  )
}


###############################################################################
### Use the Install Function For KWB-R Packages 
###############################################################################


pkgs <- pkgmeta::get_github_packages()


install_kwb_github_packages(pkgs_kwb = pkgs$name, upgrade = "always")

pkgs_recursive_dependencies <- get_recursive_pkg_dependencies(pkgs$name)
pkgs_dependencies <- get_pkg_dependencies(pkgs$name)


deps_df <-  tibble::tibble(package = names(total_deps_per_pkg), 
               n_dependencies = sapply(pkgs_dependencies, length),
               n_recursive_dependencies = sapply(pkgs_recursive_dependencies, length)) %>% 
  dplyr::arrange(dplyr::desc(n_recursive_dependencies))

Using this locally with GITHUB_PAT with private KWB-R repo scope (installation failed for 2 private repos, see #2), these are the total (recursive) dependencies:

package n_dependencies n_recursive_dependencies
kwb.flusshygiene.app 12 109
fhpredict 13 107
kwb.flusshygiene 9 100
aquanes.report 25 99
kwb.kuras 4 90
kwb.ogre.model 5 90
kwb.ogre 10 89
kwb.package 3 88
sema.berlin.app 20 88
fakin.path.app 18 86
kwb.dswt 7 86
kwb.endnote 15 84
pkgmeta 18 79
kwb.miacso 1 78
kwb.rain 5 78
kwb.misc 9 77
kwb.qmra 15 76
kwb.read 7 75
datacamp 21 68
kwb.fakin 20 65
kwb.pkgbuild 13 61
sema.berlin 7 55
kwb.twitter 6 52
kwb.umberto 9 52
kwb.monitoring 8 49
kwb.pubs 10 49
AquaNES 3 48
kwb.sema 7 48
kwb.lca 4 46
kwb.dygraph 3 44
kwb.mia.evalCritO2 2 43
kwb.readxl 6 43
kwb.mia.iw 6 42
kwb.test.datetime 2 42
kwb.base 6 41
kwb.orcid 5 39
kwb.epanet 4 38
kwb.geosalz 12 38
kwb.resilience 1 37
kwb.event 3 36
kwb.pkgstatus 8 36
kwb.site 4 35
kwb.plot 3 34
qmra.db 10 34
kwbGompitz 3 33
kwb.svn 9 31
kwb.test 2 30
kwb.demeau 9 29
kwb.pathdict 4 28
kwb.code 3 27
kwb.file 5 26
kwb.ucode 1 18
kwb.dwd 10 17
kwb.wtaq 4 17
algoliar 5 16
kwb.hantush 1 15
kwb.vs2dh 4 8
kwb.odmx 3 5
kwb.logger 4 4
kwb.odm 3 4
kwb.quantum 3 4
kwb.dwa.m150 2 3
kwb.context 2 2
kwb.db 2 2
kwb.gocr 2 2
kwb.optiwells 1 2
kwb.rerau 2 2
kwb.datetime 1 1
kwb.en13508.2 1 1
kwb.graph 1 1
kwb.iview 1 1
kwb.virtualdub 1 1
kwb.barplot 0 0
kwb.default 0 0
kwb.utils 0 0

Now deployed for public/private repos via private Gitlab repo (https://gitlab.com/kwb-r/githubdeps) and also static badge links created via redirects on Netlify:
https://kwb-githubdeps.netlify.com/