Fix index out of bounds in simplify_gt.gtable_patchwork() - #472
Open
frvirard wants to merge 1 commit into
Open
Conversation
new_height was computed from gt$widths[panel_pos$t:panel_pos$b] instead
of gt$heights[panel_pos$t:panel_pos$b]. gt$widths only has one entry per
column, so as soon as a nested block's row range exceeded its column
count - which happens whenever every height in the nested layout is an
absolute unit - the index went out of bounds and threw "index out of
bounds ('unit' subsetting)".
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.
Summary
simplify_gt.gtable_patchwork()computes the collapsed height of a nestedpatchwork from
gt$widths[panel_pos$t:panel_pos$b]instead ofgt$heights[panel_pos$t:panel_pos$b]:gt$widthsonly has one entry per column, so as soon as a nested block'srow range (
panel_pos$t:panel_pos$b) exceeds the table's column count -which happens whenever every height in the nested layout is an absolute
unit (
unit(x, "cm")/"pt"/"in", i.e.is_abs_unit()isTRUEfor allof them) - the index goes out of bounds and printing/building the
patchwork fails with:
Using a context-relative unit (e.g.
"line") for at least one heightavoids the bug, since
is_abs_unit()then returnsFALSEand the safeelsebranch is taken instead - that's how I traced it back to this line.Introduced in 556874d ("General solution to inheriting dimensions from
plot/table").
Reproducible example
Changes
R/plot_patchwork.R: one-line fix,gt$widths→gt$heightsin thenew_heightbranch.tests/testthat/test-layout.R: regression test reproducing the crashabove and asserting
patchworkGrob()no longer errors on it.NEWS.md: changelog entry.Test plan
patchwork1.3.2and passes after the fix (verified locally, both via a direct
patchworkGrob()call and viatestthat::test_file()).tests/testthat/test-layout.Rwithpkgload::load_all(); nofailures (pre-existing
vdiffrsnapshot tests skip in thisenvironment, unrelated to this change).