easystats / easystats/circus

function for checking for unused dependencies

Open
#13 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
R
Stars
6
Forks
3
PR merge metrics
No merged PRs in 30d

Description

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 https://github.com/easystats/correlation/pull/192#discussion_r657094308

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the circus package structure and existing dependency-related utilities to determine where this function belongs. Compare the proposed behavior and example output with the package's conventions, then add the dependency check and verify that declared but unused packages are reported as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.