fix [ on a worldArray with other than two layers - #58
Merged
Conversation
The number of layers was hardcoded when reshaping the extracted values, so [ only ever worked on a two-layer worldArray: a3 <- stackWorlds(w1, w2, w3) a3[1, 1] #> Error: dims [product 2] do not match the length of object [3] Use the array's own layer count instead. The sibling [,missing,missing method already did this correctly, so only the coordinate-indexed one was affected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Found while investigating #49; unrelated to it and worth landing on its own.
[on aworldArrayhardcoded the layer count when reshaping the extracted values:so it only ever worked on a two-layer array:
A single-layer
stackWorlds(w1)failed the same way. Now usesdim(x)[3].The sibling
[,worldArray,missing,missingmethod already computed this correctly, which is whya3[]worked whilea3[1, 1]did not — only the coordinate-indexed method was affected.I checked the rest of the
worldArrayAPI against a three-layer array while I was in there:of(),NLset(),[<-,[[,numLayers(),layerNames(),plot()andworld2spatRast()all already handled arbitrary layer counts. This was the only site.Tests cover one, three and four layers.
Verification
R CMD check --as-cran: 0 errors, 0 warnings, 0 notesdevtools::test(): 0 failures🤖 Generated with Claude Code