Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function for checking for unused dependencies #13

Open
bwiernik opened this issue Jun 23, 2021 · 4 comments
Open

function for checking for unused dependencies #13

bwiernik opened this issue Jun 23, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@bwiernik
Copy link

Here is a function for checking if we have unused dependencies in a package.

Throwing it here in circus might be a good home for it.

find_unused_dependencies <- function(
  dependencies = c("Depends", "Imports", "LinkingTo"),
  include_supp_files = FALSE,
  path = getwd(),
  root = NULL,
  ...,
  progress = TRUE,
  errors = c("reported", "fatal", "ignored"),
  dev = FALSE
) {
  deps <- renv::dependencies(path = path, root = root, ...,
                             progress = progress, errors = errors, dev = dev)
  if (isFALSE(include_supp_files)) {
    deps <- dplyr::filter(
      deps, 
      stringr::str_detect(Source, "DESCRIPTION") |
        stringr::str_detect(Source, "/R/")
    )
  }
  deps <- dplyr::filter(deps, Package != "R")
  deps_desc <- data.frame(Package = remotes::local_package_deps(
    pkgdir = path, 
    dependencies = dependencies
  ))
  deps_used <- dplyr::filter(deps, ! stringr::str_detect(Source, "DESCRIPTION"))
  deps_orphan <- dplyr::anti_join(deps_desc, deps_used, by = "Package")
  return(deps_orphan)
}
find_unused_dependencies()
# Finding R package dependencies ... Done!
#   Package
# 1 poorman

dependencies says which dependencies fields to check. See ?remotes::local_package_deps.
include_supp_files: If FALSE, only check for dependencies in DESCRIPTION and files in /R/ (excluding tests, vignettes, /WIP/, README, etc.). If TRUE, all files are checked.

Originally posted by @bwiernik in easystats/correlation#192 (comment)

@IndrajeetPatil IndrajeetPatil added the enhancement New feature or request label Jun 23, 2021
@strengejacke
Copy link
Member

Wouldn't this be better located in easystats?

@bwiernik
Copy link
Author

Don't know why a user would need it?

@strengejacke
Copy link
Member

Circus is just a collection of model objects, w/o much functionality

@bwiernik
Copy link
Author

I was just thinking that a function only useful for us as developers could go in this package with other stuff only us developers use. No strong opinion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants