Skip to content

Commit

Permalink
fix: improve detection of dependencies - fix #34
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Oct 20, 2023
1 parent 04bf40f commit c2c58d3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 18 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
the `CITATION.cff` file
* Modify `add_citation()` to create two additional files: `CITATION.cff` and
`.github/workflows/update-citation-cff.yaml`
* Improve detection of dependencies in `get_deps_*()` functions


# rcompendium 1.1

Expand Down
97 changes: 79 additions & 18 deletions R/utils-deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,38 @@ get_deps_in_functions_r <- function() {

## Functions called as pkg::fun() ----

pattern <- "[A-Z|a-z|0-9|\\.]{1,}::[A-Z|a-z|0-9|\\.|_]{1,}"
pattern <- paste0("[A-Z|a-z|0-9|\\.]{1,}\\s{0,}",
"::",
"\\s{0,}[A-Z|a-z|0-9|\\.|_]{1,}")

funs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

funs <- gsub("\\s", "", funs)


## Attached Packages ----

pattern <- c(paste0("library\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"),
paste0("require\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"))
pattern <- paste0(pattern, collapse = "|")

pkgs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

pkgs <- gsub("library\\(|require\\(|\"|\'", "", pkgs)


## Merge dependencies ----

funs <- sort(unique(c(funs, pkgs)))


if (!length(funs)) {

Expand Down Expand Up @@ -185,24 +211,33 @@ get_deps_in_examples <- function() {

## Functions called as pkg::fun() ----

pattern <- "[A-Z|a-z|0-9|\\.]{1,}::[A-Z|a-z|0-9|\\.|_]{1,}"
pattern <- paste0("[A-Z|a-z|0-9|\\.]{1,}\\s{0,}",
"::",
"\\s{0,}[A-Z|a-z|0-9|\\.|_]{1,}")

funs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

funs <- gsub("\\s", "", funs)


## Attached Packages ----

pattern <- c("library\\(([A-Z|a-z|0-9|\\.]{1,}|\"[A-Z|a-z|0-9|\\.]{1,}\")",
"require\\(([A-Z|a-z|0-9|\\.]{1,}|\"[A-Z|a-z|0-9|\\.]{1,}\")")
pattern <- c(paste0("library\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"),
paste0("require\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"))
pattern <- paste0(pattern, collapse = "|")

pkgs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

pkgs <- gsub("library\\(|require\\(|\"", "", pkgs)
pkgs <- gsub("\\s", "", pkgs)
pkgs <- gsub("library\\(|require\\(|\"|\'", "", pkgs)


## Merge dependencies ----
Expand Down Expand Up @@ -289,24 +324,32 @@ get_deps_extra <- function(compendium = NULL) {

## Functions called as pkg::fun() ----

pattern <- "[A-Z|a-z|0-9|\\.]{1,}::[A-Z|a-z|0-9|\\.|_]{1,}"
pattern <- paste0("[A-Z|a-z|0-9|\\.]{1,}\\s{0,}",
"::",
"\\s{0,}[A-Z|a-z|0-9|\\.|_]{1,}")

funs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

funs <- gsub("\\s", "", funs)


## Attached Packages ----

pattern <- c("library\\(([A-Z|a-z|0-9|\\.]{1,}|\"[A-Z|a-z|0-9|\\.]{1,}\")",
"require\\(([A-Z|a-z|0-9|\\.]{1,}|\"[A-Z|a-z|0-9|\\.]{1,}\")")
pattern <- c(paste0("library\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"),
paste0("require\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"))
pattern <- paste0(pattern, collapse = "|")

pkgs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

pkgs <- gsub("library\\(|require\\(|\"", "", pkgs)
pkgs <- gsub("library\\(|require\\(|\"|\'", "", pkgs)


## Merge dependencies ----
Expand Down Expand Up @@ -397,31 +440,41 @@ get_deps_in_vignettes <- function() {

## Remove inline code (not evaluated) ----

pattern <- "`[A-Z|a-z|0-9|\\.]{2,}::[A-Z|a-z|0-9|\\.|_]{1,}"
pattern <- paste0("`[A-Z|a-z|0-9|\\.]{1,}\\s{0,}",
"::",
"\\s{0,}[A-Z|a-z|0-9|\\.|_]{1,}")

x <- lapply(x, function(x) gsub(pattern, "", x))


## Functions called as pkg::fun() ----

pattern <- "[A-Z|a-z|0-9|\\.]{1,}::[A-Z|a-z|0-9|\\.|_]{1,}"
pattern <- paste0("[A-Z|a-z|0-9|\\.]{1,}\\s{0,}",
"::",
"\\s{0,}[A-Z|a-z|0-9|\\.|_]{1,}")

funs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

funs <- gsub("\\s", "", funs)


## Attached Packages ----

pattern <- c("library\\(([A-Z|a-z|0-9|\\.]{1,}|\"[A-Z|a-z|0-9|\\.]{1,}\")",
"require\\(([A-Z|a-z|0-9|\\.]{1,}|\"[A-Z|a-z|0-9|\\.]{1,}\")")
pattern <- c(paste0("library\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"),
paste0("require\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"))
pattern <- paste0(pattern, collapse = "|")

pkgs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

pkgs <- gsub("library\\(|require\\(|\"", "", pkgs)
pkgs <- gsub("library\\(|require\\(|\"|\'", "", pkgs)


## Merge dependencies ----
Expand Down Expand Up @@ -505,24 +558,32 @@ get_deps_in_tests <- function() {

## Functions called as pkg::fun() ----

pattern <- "[A-Z|a-z|0-9|\\.]{1,}::[A-Z|a-z|0-9|\\.|_]{1,}"
pattern <- paste0("[A-Z|a-z|0-9|\\.]{1,}\\s{0,}",
"::",
"\\s{0,}[A-Z|a-z|0-9|\\.|_]{1,}")

funs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

funs <- gsub("\\s", "", funs)


## Attached Packages ----

pattern <- c("library\\(([A-Z|a-z|0-9|\\.]{1,}|\"[A-Z|a-z|0-9|\\.]{1,}\")",
"require\\(([A-Z|a-z|0-9|\\.]{1,}|\"[A-Z|a-z|0-9|\\.]{1,}\")")
pattern <- c(paste0("library\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"),
paste0("require\\s{0,}\\(\\s{0,}([A-Z|a-z|0-9|\\.]{1,}|",
"\"\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\"|",
"\'\\s{0,}[A-Z|a-z|0-9|\\.]{1,}\\s{0,}\')"))
pattern <- paste0(pattern, collapse = "|")

pkgs <- unlist(lapply(x, function(x) {
unlist(stringr::str_extract_all(x, pattern))
}))

pkgs <- gsub("library\\(|require\\(|\"", "", pkgs)
pkgs <- gsub("library\\(|require\\(|\"|\'", "", pkgs)


## Merge dependencies ----
Expand Down

0 comments on commit c2c58d3

Please sign in to comment.