Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the minimum version of R required for a given package?

Tags:

r

How can I check what version of R is needed for a list of packages? Ideally something like this

minimumRVersion <- function(packageList = c(), return=c("list", "min", "mine")) {
# code to collate a list of minimum versions of R
# required for the listed packages.
# Optionally return min(list) or "is my R high enough?
return(result) 
}

minVersion("RcppEigen")
# 2.15.1

minVersion(c("RcppEigen","OpenMx"), "min")
# 3.0
like image 947
tim Avatar asked Sep 27 '22 18:09

tim


1 Answers

You can use the packageDescription function, which allows you to get package requirements.

I wrote a quick-and-dirty solution, feel free to improve on that!

minimumRVersion <- function(packageList)
  {
  requirements <- NULL

  for (p in packageList)
    {
    # Get dependencies for the package
    dep <- packageDescription(p, fields = "Depends")

    if (!is.na(dep))
      {
      # dep will be something like:
      # "R (>= 3.1.0), grDevices, graphics, stats, utils"
      # split by comma
      dep <- unlist(strsplit(dep, ","))
      # Find requirement for R (may not exist)
      r.dep <- dep[grep("R \\(", dep)]
      if (!length(r.dep))
          r.dep <- NA
      }
    else
          r.dep <- NA

    requirements <- c(requirements, r.dep)
    }

  requirements
  }

Calling:

minimumRVersion(c("nlme", "MASS", "bootstrap", "knitr", "Hmisc"))

Returns:

[1] " R (>= 3.0.0)" "R (>= 3.1.0)" " R (>= 2.10.0)" "R (>= 3.0.2)"  NA              
like image 96
nico Avatar answered Nov 15 '22 06:11

nico