-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# getDependencyData ------------------------------------------------------------ | ||
|
||
#' Get Package Dependency Data from Package Database | ||
#' | ||
#' @param db package data base as e.g. returned by | ||
#' \code{\link{getCranPackageDatabase}} | ||
#' @param fields types of dependencies to be considered. Default: | ||
#' \code{c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")} | ||
#' @export | ||
getDependencyData <- function( | ||
db, | ||
fields = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances") | ||
) | ||
{ | ||
stopifnot(`db must be a matrix or a data frame` = length(dim(db)) == 2L) | ||
|
||
db <- as.data.frame(db) | ||
packages <- selectColumns(db, "Package") | ||
|
||
deps <- lapply(fields, function(field) { | ||
catAndRun( | ||
sprintf("Analysing %s field", field), | ||
packages %>% | ||
toDependencyData(selectColumns(db, field)) %>% | ||
cbind( | ||
type = tolower(field), | ||
reverse = FALSE | ||
) | ||
) | ||
}) %>% | ||
rbindAll() %>% | ||
fullySorted() %>% | ||
moveColumnsToFront(c("package", "type")) | ||
} | ||
|
||
# toDependencyData ------------------------------------------------------------- | ||
toDependencyData <- function(packages, strings) | ||
{ | ||
stopifnot(length(packages) == length(strings)) | ||
|
||
# Split dependency strings at comma (after removing new line or space) | ||
parts <- strsplit(gsub("\n|\\s+", "", strings), ",") | ||
|
||
data.frame( | ||
package = rep(packages, lengths(parts)), | ||
splitDependency(unlist(parts)) | ||
) | ||
} | ||
|
||
# splitDependency -------------------------------------------------------------- | ||
splitDependency <- function(x) | ||
{ | ||
stopifnot(`No spaces allowed!` = !any(grepl("\\s", x))) | ||
|
||
pattern <- "^([^(]+)(\\(([<>=]+)(.*)\\))?" | ||
matches <- is.na(x) | grepl(pattern, x) | ||
|
||
if (any(!matches)) { | ||
stopFormatted( | ||
"Non-matching dependency string: '%s'", x[!matches][1L] | ||
) | ||
} | ||
|
||
cbind( | ||
dep_full = x, | ||
extractSubstring(pattern, x, index = c( | ||
dep_name = 1L, | ||
dep_version_op = 3L, | ||
dep_version_no = 4L | ||
)) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.