R/list_LEEF_packages.R

Defines functions list_LEEF_packages

Documented in list_LEEF_packages

#' List packages on which LEEF depends from the LEEF-UZH repo
#'
#' This function is a wrapper around \code{tools::package_dependencies("LEEF",
#' which = "all", recursive = TRUE)} which returns only the packages which
#' contain \bold{.LEEF} or \bold{LEEF.} and the package \bold{LEEF} itself.
#'
#' This function is a convenience function and only returns useful results when
#' all packages which are dependencies of the \code{LEEF} package are prefixed
#' with \code{LEEF.} or postficxed with \code{.LEEF}.
#' @param recursive logical: should (reverse) dependencies of (reverse)
#'   dependencies (and so on) be included? defaults to \code{TRUE}
#' @param versions logical: should versions be returned as well.
#'
#' @return list of all packages which are installed which contain \bold{.LEEF}
#'   or \bold{LEEF.} and the package \bold{LEEF} itself
#' @export
#' @importFrom tools package_dependencies
#' @importFrom drat addRepo
#'
#' @examples
#' \dontrun{
#' list_LEEF_packages()
#' }
list_LEEF_packages <- function(
  recursive = TRUE,
  versions = FALSE
) {
  drat::addRepo("LEEF-UZH")
  pkgs <- tools::package_dependencies("LEEF.2", which = "all", recursive = recursive)
  pkgs <- c(
    "LEEF.2",
    grep("LEEF.|.LEEF", pkgs$LEEF, value = TRUE)
  )

  if (versions) {
    pkgs <- as.vector(
      sapply(
        pkgs,
        function(x) {
          paste0(x, ": ", packageVersion(x))
        }
      )
    )
  }
  return( pkgs )
}
LEEF-UZH/LEEF documentation built on Feb. 10, 2025, 5:20 a.m.