Repository navigation
[Linting Rule] Package Hooks
Generated from 'wiki-linter.ts' on 2026-10-25, 09:29:25 UTC (v2.16.6), do not edit directly.
Package Hooks [overview]
This rule ports the following steps of R CMD check (see the conformance table for the legend):
| # | Step | Coverage | Note |
|---|---|---|---|
| 37 | R code for possible problems (book) | 🟩⭐ | ⭐ also quick fixes, deprecated arguments, environments resolved through variables, hooks followed into callees |
| 42 | whether startup messages can be suppressed (book) | 🔷⭐ | ⭐ also follows the hooks into the package functions they call output in package hooks not sent through packageStartupMessage |
| 43 | whether the namespace can be unloaded cleanly (book) | 🔷 | only hook arguments and misplaced library.dynam.unload calls |
| 44 | package namespace information (book) | 🔶 | |
| 82 | whether the package can be unloaded cleanly (book) | 🔷 | only hook arguments and misplaced library.dynam.unload calls |
This rule is a best-effort rule.
Finds problems in .onLoad, .onAttach, .onDetach, and .Last.lib: argument lists, attaching packages, output other than packageStartupMessage(), installed.packages(), misplaced library.dynam() calls, and the obsolete .First.lib. Follows calls into the package's own functions.
This linting rule is implemented in src/linter/rules/cmd-check/package-hooks.ts.
Linting rules can be configured by passing a configuration object to the linter query as shown in the example below.
The package-hooks rule accepts the following configuration options:
-
allowedOutput
functions that may emit output in a startup hook nonetheless, as the user can silence them otherwise (defaultwarning)
R CMD check #37, #42 -
followCalls
also report what the hook does through functions of the package it calls, whichR CMD checkdoes not see (defaulttrue)
R CMD check #37, #42 -
startupMessageFunctions
functions that print startup messages the way R wants them to, which are only allowed in.onAttach
R CMD check #37, #42 -
unsafeCalls
functions too costly or unsafe to call in a startup hook (defaultinstalled.packages)
R CMD check #37
.onLoad <- function(libname, pkgname) {
library(stats)
cat("Loading")
}
.onAttach <- function(libname, pkgname) message("Welcome!")The linting query can be used to run this rule on the above example:
[ { "type": "linter", "rules": [ { "name": "package-hooks", "config": {} } ] } ]Results (prettified and summarized):
Query: linter (3 ms)
╰ Package Hooks (package-hooks):
╰ certain:
╰ .onLoad: search-path (library) at 2.2-15
╰ .onLoad: output (cat) at 3.2-15
╰ .onAttach: output (message) at 5.41-59 (1 quick fix(es) available)
More examples are the test cases in test/functionality/linter/cmd-check/lint-package-hooks.test.ts.
Currently maintained by Florian Sihler and Oliver Gerstl at Ulm University
Email | GitHub | Penguins | Portfolio
- 🧑💻 Developer Onboarding
- 💻 Setup
- 👓 Overview
- 🪟 Interfacing with flowR
- 🌋 Core
- 🧹 Testing & Linting (Benchmark Page)
⁉️ FAQ- ℹ️ Extra Information