Skip to content

[Linting Rule] Dependency Declaration

github-actions[bot] edited this page Oct 25, 2026 · 1 revision

Generated from 'wiki-linter.ts' on 2026-10-25, 09:29:25 UTC (v2.16.6), do not edit directly.

Dependency Declaration [overview]

bug cmd-check 27–33, 53, 77, 83, 85, 88 reproducibility

This rule ports the following steps of R CMD check (see the conformance table for the legend):

# Step Coverage Note
27 package dependencies (book) 🔷 availability and versions asked of the signature database instead of the repositories
28 dependencies in R code (book) 🟩⭐ ⭐ also resolves package names through variables and knows the loaders of other packages
29 for unstated dependencies in tests (book) 🟩
30 for unstated dependencies in examples (book) 🟩
31 for unstated dependencies in vignettes (book) 🟩⭐ ⭐ also packages named in \VignetteEngine
32 whether the package can be loaded with stated dependencies (book) 🔷
33 whether the namespace can be loaded with stated dependencies (book) 🔷
53 examples (book) 🔷⭐ ⭐ also T and F in the examples
parses the examples and checks what they call, without running them
77 whether package can be installed (book) 🔷⭐ ⭐ also compiled code never loaded for lack of useDynLib
useDynLib and src/ in agreement, headers from LinkingTo, undefined exports
83 tests (book) 🔷⭐ ⭐ also testthat tests without a runner, runners testing another package
tests are not run, only checked for runners and syntax
85 running R code from vignettes (book) 🔷 vignette code that does not parse
88 examples with --run-donttest (book) 🔷⭐ ⭐ also T and F in the examples
the \donttest code is checked like all examples

This rule is a best-effort rule.

Finds packages the code, tests, examples, or vignettes use without the DESCRIPTION declaring them, Imports nothing imports from, library() calls in package code, own ::: calls, and undeclared VignetteBuilder or RdMacros packages. Package names are resolved through variables.
This linting rule is implemented in src/linter/rules/cmd-check/dependency-declaration.ts.

Configuration

Linting rules can be configured by passing a configuration object to the linter query as shown in the example below. The dependency-declaration rule accepts the following configuration options:

  • checkAvailability
    report declared packages the signature database does not know or cannot satisfy, which R CMD check asks the repositories about (default true)
    R CMD check #27
  • checkOtherCode
    check the packages the tests, vignettes, and examples use (default true)
    R CMD check #29, #30, #31
  • headerOnlyPackages
    packages that only provide C/C++ headers and hence belong into LinkingTo, a note R CMD check gives for CRAN submissions (default BH, RcppArmadillo, RcppEigen)
    R CMD check #27
  • ignoreWithin
    functions whose arguments run elsewhere, so the packages loaded there are no dependency of the package (default clusterEvalQ)
    R CMD check #28
  • reportDependsNotImported
    report packages in Depends the NAMESPACE imports nothing from, a note R CMD check only gives for CRAN submissions (default false)
    R CMD check #28
  • reportLibraryCalls
    report every library/require call in package code, even for declared packages (default true, as R CMD check)
    R CMD check #28

Examples

A project with the code R/code.R:

f <- function(df) {
	library(dplyr)
	tidyr::drop_na(df)
}

and the files

DESCRIPTION:

Package: pkg
Version: 1.0
Title: A Package
License: MIT

The linting query can be used to run this rule on the above example:

[ { "type": "linter",   "rules": [ { "name": "dependency-declaration",     "config": {} } ] } ]

Results (prettified and summarized):

Query: linter (8 ms)
   ╰ Dependency Declaration (dependency-declaration):
       ╰ certain:
           ╰ undeclared-attach of dplyr at /pkg/R/code.R:2.2-15
           ╰ library-in-package of dplyr at /pkg/R/code.R:2.2-15
           ╰ undeclared-namespace of tidyr at /pkg/R/code.R:3.2-19

More examples are the test cases in test/functionality/linter/cmd-check/lint-dependency-declaration.test.ts.

Clone this wiki locally