Skip to content

feat: package_check() on_missing levels and once - #193

Merged
jiajic merged 1 commit into
devfrom
feat/package-check-on-missing
Oct 22, 2026
Merged

jiajic merged 1 commit into
devfrom
feat/package-check-on-missing

Conversation

@jiajic

@jiajic jiajic commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

package_check() gains two arguments:

  • on_missing = c("error", "warning", "message", "none"): what to do when a package is missing. Every level but "error" returns FALSE, so callers can fall back:
    if (package_check("png", on_missing = "message")) png::readPNG(f)
  • once = FALSE: when TRUE, the warning or message is shown once per session, through rlang's .frequency = "once", the same mechanism GiottoDisk already uses for its engine hints. The id is keyed on the package names, so every caller asking about the same package shares it. Errors are always raised.

A version shortfall (installed, but below a requested floor) is reported at the same level. "error" still reports it as a warning, as before, and the call returns TRUE since the package is there.

Fix: package_check() returned TRUE even when an optional package was missing, so if (package_check(x, optional = TRUE)) never skipped its body. GiottoVisuals' show_saved_plot guards in aux_save.R (png/tiff) rely on that and error in png::readPNG() instead. They now work without changes.

Deprecation: optional is soft-deprecated. TRUE maps to "message" and FALSE to "error", and a vector errors if any entry is FALSE, as before. Passing both optional and on_missing errors. The only callers that pass it are GiottoVisuals' 4 optional = TRUE sites and one optional = FALSE in Giotto's spdep.R. Those move over once this is released.

Other changes:

  • rlang added to Imports. It was already installed through lifecycle.
  • Version bumped to 0.2.9 so downstream packages can pin the new arguments. dev has been 0.2.8 since suite_install(): tilework from dev until 1.0.1 is on CRAN #189, so 0.2.8 alone doesn't guarantee them.
  • The optional docs, which had the error/message behaviour reversed, are replaced.

Tests: new cases for each level, once, version shortfalls and the deprecated alias. The full suite has the same 7 failures as dev (pip:scipy and test_pyutils.R, which need Python packages not in the local env).

🤖 Generated with Claude Code

Missing packages now return FALSE at every level but "error".
optional is deprecated in favour of on_missing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant