@@ -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+
56101list_inst <- function () {
57102 libs <- unique(c(.Library.site , .Library ))
58103 inst <- unique(row.names(utils :: installed.packages(libs )))
0 commit comments