From J.Gorecki at wit.edu.pl  Tue Jun 14 16:54:28 2016
From: J.Gorecki at wit.edu.pl (=?UTF-8?B?SmFuIEfDs3JlY2tp?=)
Date: Tue, 14 Jun 2016 15:54:28 +0100
Subject: [Rd] new function to tools/utils package: dependencies based on
 DESCRIPTION file
Message-ID: <CABE2sp6e_kyX4vhR-uLAqpwNZxDyG-FD+AMBHE0uXp=c+UPQhw@mail.gmail.com>

Hi all,

Packages tools and utils have a lot of useful stuff for R developers.
I find one task still not as straightforward as it could. Simply to
extract dependencies of a package from DESCRIPTION file (before it is
even installed to library). This would be valuable in automation of CI
setup in a more meta-data driven way.
The simple function below, I know it is short and simple, but having
it to be defined in each CI workflow is a pain, it could be already
available in tools or utils namespace.

package.dependencies.dcf <- function(file = "DESCRIPTION", which =
c("Depends","Imports","LinkingTo")) {
    stopifnot(file.exists(file), is.character(which))
    which_all <- c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")
    if (identical(which, "all"))
        which <- which_all
    else if (identical(which, "most"))
        which <- c("Depends", "Imports", "LinkingTo", "Suggests")
    stopifnot(which %in% which_all)
    dcf <- read.dcf(file, which)
    # parse fields
    raw.deps <- unlist(strsplit(dcf[!is.na(dcf)], ",", fixed = TRUE))
    # strip stated dependency version
    deps <- trimws(sapply(strsplit(trimws(raw.deps), "(", fixed =
TRUE), `[[`, 1L))
    # exclude base R pkgs
    base.pkgs <- c("R", rownames(installed.packages(priority = "base")))
    setdiff(deps, base.pkgs)
}

This allows to easily install all package dependencies just based on
DESCRIPTION file, so simplify that in custom CI workflows to:

if (length(pkgs<-package.dependencies.dcf(which="all"))) install.packages(pkgs)

And would not require to install custom packages or shell scripts.

Regards,
Jan Gorecki



[Rd] new function to tools/utils package: dependencies based on DESCRIPTION file
=?UTF-8?B?SmFuIEfDs3JlY2tp?=