Skip to content

Commit dd0ffcd

Browse files
committed
add sysreqs function
1 parent 7fe308f commit dd0ffcd

5 files changed

Lines changed: 82 additions & 1 deletion

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: bspm
22
Type: Package
33
Title: Bridge to System Package Manager
4-
Version: 0.5.8
4+
Version: 0.5.8.1
55
Authors@R: c(
66
person("Iñaki", "Ucar", email="iucar@fedoraproject.org",
77
role=c("aut", "cph", "cre"), comment=c(ORCID="0000-0001-6403-5550")))

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export(install_sys)
88
export(moveto_sys)
99
export(remove_sys)
1010
export(shadowed_packages)
11+
export(sysreqs)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# devel
2+
3+
- Add `sysreqs()` function, based on the cran4linux/sysreqs database.
4+
15
# bspm 0.5.8
26

37
- Fix "invalid escape sequence" SyntaxWarning (@pekkarr in #84).

R/utils.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,51 @@ shadowed_packages <- function(lib.loc=NULL) {
5353
shadow
5454
}
5555

56+
#' Find System Requirements
57+
#'
58+
#' Compute the system requirements (system libraries; operating system packages)
59+
#' required by a set of R packages.
60+
#'
61+
#' @param pkgs character vector of R package names.
62+
#' @param ... unused, reserved for future expansion.
63+
#' @param type type of requirements: build- or run-time requirements, or both.
64+
#' @param distro name of the Linux distribution; if nothing is provided, the
65+
#' function tries to detect it automatically.
66+
#' @param collapse whether to collapse the requirements into a single line.
67+
#' @return A character vector of system requirements.
68+
#'
69+
#' @details This function relies on https://github.com/cran4linux/sysreqs.
70+
#'
71+
#' @export
72+
sysreqs <- function(pkgs, ..., type=c("build", "run"), distro=NULL, collapse=FALSE) {
73+
type <- match.arg(type, several.ok=TRUE)
74+
75+
if (is.null(distro)) {
76+
distro <- system(". /etc/os-release && echo $ID $ID_LIKE", intern=TRUE)
77+
distro <- strsplit(distro, " ")[[1]]
78+
}
79+
distro <- tolower(distro)
80+
81+
if (any(distro %in% c("fedora", "rhel")))
82+
distro <- "fedora_rhel"
83+
else if (any(distro %in% c("debian", "ubuntu")))
84+
distro <- "debian_ubuntu"
85+
else stop("Distro ", distro, " not supported")
86+
87+
url <- "https://raw.githubusercontent.com/cran4linux/sysreqs/refs/heads/main"
88+
if (!file.exists(srqdb.file <- file.path(tempdir(), "sysreqs.csv")))
89+
download.file(file.path(url, "sysreqs.csv"), srqdb.file, quiet=TRUE)
90+
srqdb <- utils::read.csv(srqdb.file)
91+
if (!file.exists(pkgdb.file <- file.path(tempdir(), "pkgdb.csv")))
92+
download.file(file.path(url, "pkgdb.csv"), pkgdb.file, quiet=TRUE)
93+
pkgdb <- utils::read.csv(pkgdb.file)
94+
95+
reqs <- unlist(strsplit(unlist(pkgdb[pkgdb$name %in% pkgs, type]), " "))
96+
reqs <- unique(srqdb[srqdb$name %in% reqs, distro])
97+
if (collapse) reqs <- paste(reqs, collapse=" ")
98+
reqs
99+
}
100+
56101
list_inst <- function() {
57102
libs <- unique(c(.Library.site, .Library))
58103
inst <- unique(row.names(utils::installed.packages(libs)))

man/sysreqs.Rd

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)