test: skip image snapshots when raster is not installed (fixes the nosuggests leg) - #46
Merged
Merged
Conversation
The image snapshots in test-Plot-snapshots.R were recorded with the full
Suggests set installed, and they are not portable to a run without it --
not because the rendering differs, but because the *names* do.
Several tests build a `rasts` list and then double its length inside
`if (requireNamespace("raster", quietly = TRUE))`. Snapshot file names come
from `fn()` (helper-testInit.R), which pulls from a running `counter` over
those lists. Drop `raster` and every list shortens, so each name after the
first raster block lines up against a different plot. "internal functions
in Plot" additionally computes `val <- (testNum - 1) %% (length(rasts) / 2) + 1`,
hard-coding the doubling, so without raster it renders plots 1 and 2 twice
and never renders 3 or 4.
This is exactly the `_R_CHECK_DEPENDS_ONLY_` leg that PredictiveEcology/actions'
shared R-CMD-check matrix runs: 11 failures there, all in this file, all of
them a reference image compared against the wrong plot.
Maintaining a second set of reference images for that configuration would be
a lot of pixels for no extra signal, so skip the image comparisons when
raster is absent. The nosuggests leg keeps its real purpose -- the package
loads and its non-image tests pass without Suggests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011kpoQV6nNqcknk16R3RzBB
This was referenced Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
skip_if_not_installed("raster")in the ninetest_that()blocks oftests/testthat/test-Plot-snapshots.Rthat take image snapshots, plus a header comment explaining why.Why
The reference images in
_snaps/Plot-snapshots/were recorded with the full Suggests set installed, and they are not portable to a run without it — not because the rendering differs, but because the names do.Several tests build a
rastslist and then double its length:Snapshot names come from
fn()(helper-testInit.R:85), which reads a runningcounterincremented once perosesentry per plot. Droprasterand every one of those lists halves, so the counter runs shorter and every snapshot name after the firstrequireNamespace("raster")block lines up against a different plot.test_that("internal functions in Plot")has a second, sharper version of the same assumption:The
/ 2hard-codes the doubling. Withoutraster,length(rasts)is 4, sovalcycles1, 2, 1, 2— plots 3 and 4 are never rendered, and their reference images are compared against plots 1 and 2.Effect
This is precisely the
_R_CHECK_DEPENDS_ONLY_(nosuggests) leg that the sharedPredictiveEcology/actionsR-CMD-check matrix runs. It reportsFAIL 11, and all eleven are in this one file::189"internal functions in Plot"length(rasts) / 2assumption:327"Plot 2 is not error-free":396"Plot 2 is not error-free":703"Plot lists":612"rePlot doesn't work"Maintaining a second full set of reference images for a Suggests-free configuration would be a lot of pixels for no extra signal, so the image comparisons are skipped there instead. The
nosuggestsleg keeps its actual purpose: the package loads and its non-image tests pass without Suggests.Verification
The
nosuggestsleg does not exist ondevelopment's current workflow — it only appears once #44 lands — so this PR's own CI cannot exercise it. What it can show is that the guard is a no-op whererasteris installed, and it is: run 33897721026 reportsFAIL 2 | SKIP 3 | PASS 173onubuntu-latest (release)— byte for byte the same counts, the same two failures and the same three skips as the pre-change baseline. No test was silently skipped.Those two remaining failures are the ones #45 fixes; this branch is deliberately independent of it.
Note
This does not fix the
length(rasts) / 2bug itself — with the guard in placerasteris always present in these tests, so the expression is always correct. Its sibling at:302/:321already uses the safe(1 + hasRasterLayer)idiom if you would rather make them match; left alone here to keep the change surgical.🤖 Generated with Claude Code
https://claude.ai/code/session_011kpoQV6nNqcknk16R3RzBB