Skip to content

Commit

Permalink
feat: add utilities functions to get deps in description
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Oct 27, 2023
1 parent 77b268d commit fc83dc9
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions R/utils-deps.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#' **Detect dependencies in Depends field of DESCRIPTION**
#'
#' @noRd

get_deps_in_depends <- function() {

descr <- read_descr_file()

if (!is.null(descr$"Depends")) {

deps <- get_deps_in_field(descr$"Depends")

} else {

deps <- NULL
}

deps
}



#' **Detect dependencies in Imports field of DESCRIPTION**
#'
#' @noRd

get_deps_in_imports <- function() {

descr <- read_descr_file()

if (!is.null(descr$"Imports")) {

deps <- get_deps_in_field(descr$"Imports")

} else {

deps <- NULL
}

deps
}



#' **Detect dependencies in Suggests field of DESCRIPTION**
#'
#' @noRd

get_deps_in_suggests <- function() {

descr <- read_descr_file()

if (!is.null(descr$"Suggests")) {

deps <- get_deps_in_field(descr$"Suggests")

} else {

deps <- NULL
}

deps
}



#' **Remove R minimum version from list of packages**
#'
#' @noRd

remove_r_min_version <- function(dependencies) {

r_version <- grep("^R\\s{0,}\\(", dependencies)

if (length(r_version)) {
dependencies <- dependencies[-r_version]
}

dependencies
}



#' **Extract and clean list of packages in a particular DESCRIPTION field**
#'
#' @noRd

get_deps_in_field <- function(field) {

deps <- unlist(strsplit(field, "\n\\s{0,}|,|,\\s{0,}"))

deps <- gsub("\\(\\s{0,}", " (", deps)
deps <- gsub("\\s{0,}\\)", ")", deps)
deps <- gsub("=", "= ", deps)
deps <- gsub(">", "> ", deps)
deps <- gsub("<", "< ", deps)

deps <- gsub("\\s{0,}\\)", ")", deps)
deps <- gsub("\\s+", " ", deps)
deps <- trimws(deps)

deps <- gsub("< =", "<=", deps)
deps <- gsub("> =", ">=", deps)
deps <- gsub("= =", "==", deps)

deps <- deps[!(deps == "")]

remove_r_min_version(deps)
}

0 comments on commit fc83dc9

Please sign in to comment.