Skip to content

1095 intermediate nesting - #1111

Draft
gmbecker wants to merge 36 commits into
mainfrom
1095_intermediate_nesting
Draft

1095 intermediate nesting#1111
gmbecker wants to merge 36 commits into
mainfrom
1095_intermediate_nesting

Conversation

@gmbecker

Copy link
Copy Markdown
Collaborator

Intermediate nesting behavior, testing and documentation

gmbecker and others added 18 commits June 16, 2026 08:36
…1109)

- Redocument using the up to date roxygen 8.0.0 (reverting most of the
changes)
- Added tests for `at_sibling`
- Fixed multivariable label validation and made cut-split labels visible
only for `at_sibling` branches.

---------

Signed-off-by: David Muñoz Tord <david.munoztord@mailbox.org>
Co-authored-by: Joe Zhu <joe.zhu@roche.com>
Co-authored-by: shajoezhu <3692541+shajoezhu@users.noreply.github.com>
@gmbecker

Copy link
Copy Markdown
Collaborator Author

@munoztd0 I've moved your tests to test-nesting.R along with the ones I had locally, can you please convert the ones you have to use the path_count/tt_normalize_row_path pattern when you're checking for existence of sub structures?

@munoztd0
munoztd0 marked this pull request as ready for review August 24, 2026 14:35
@munoztd0
munoztd0 marked this pull request as draft August 24, 2026 14:36
@munoztd0
munoztd0 marked this pull request as ready for review August 24, 2026 14:59
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

badge

Code Coverage Summary

Filename                     Stmts    Miss  Cover    Missing
-------------------------  -------  ------  -------  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
R/00tabletrees.R               900      70  92.22%   20, 72-76, 138, 141, 472, 563-564, 567, 729, 835, 962-963, 1065, 1068, 1070-1071, 1089-1092, 1112, 1227-1230, 1328-1333, 1496, 1597-1600, 1723-1726, 1763-1766, 1772-1777, 1837, 1844, 1955, 1962, 1965, 2077, 2090, 2093-2096, 2099-2102, 2132, 2165-2166
R/as_html.R                    172      25  85.47%   5-10, 80, 152-157, 162-167, 182-186, 273
R/colby_constructors.R         543      26  95.21%   163, 179, 958-962, 964-968, 1050, 1140, 1301, 1367, 1378, 1386, 1389, 1414, 1435, 1581, 1812-1815
R/compare_rtables.R             83      17  79.52%   93-96, 99-102, 115-118, 137, 156-157, 188, 193
R/custom_split_funs.R          265      40  84.91%   127, 132, 138-143, 156, 173-177, 353-358, 375-380, 456, 502, 518-521, 537, 599, 609-610, 612, 624, 668, 693
R/default_split_funs.R         287      22  92.33%   272, 335-338, 349-350, 352, 354, 551-555, 619-622, 685-688
R/format_rcell.R                17       1  94.12%   47
R/indent.R                      13       2  84.62%   40-41
R/index_footnotes.R             66       0  100.00%
R/make_split_fun.R             166      30  81.93%   22-26, 36-39, 52-55, 58-61, 115, 119, 267, 270-273, 278-281, 366, 375, 377, 379, 430
R/make_subset_expr.R           137      14  89.78%   77-92, 169-177, 213, 302, 306, 315
R/nesting_impl.R               229      28  87.77%   73, 99, 112, 239-243, 284-287, 319, 323-327, 345, 414, 477-480, 547-550
R/summary.R                    144      38  73.61%   35, 80, 178-220, 269, 315-331, 366, 397
R/tree_accessors.R            1263     141  88.84%   110, 139-140, 210, 233, 263, 281, 300-304, 324, 346-349, 476, 503-504, 790-796, 943, 962, 988, 1040, 1116-1117, 1162, 1197, 1235-1240, 1299, 1373-1377, 1395-1404, 1482, 1630, 1652-1653, 1663, 1714, 1735-1740, 1761-1766, 1902, 1943, 2042, 2149, 2162, 2176, 2192, 2201, 2211-2215, 2265-2270, 2473, 2483-2486, 2496, 2521-2524, 2531, 2533-2536, 2658, 2692-2693, 2750, 3054, 3415, 3531, 3565-3590, 3681-3689, 3850, 3924-3930, 4235, 4359, 4444-4449, 4455, 4479-4484, 4532, 4557-4581, 4610-4616
R/tt_afun_utils.R              419      33  92.12%   60, 182, 189, 198-212, 280, 288-289, 507, 515-518, 600-604, 624, 638-640
R/tt_as_df.R                   400      23  94.25%   101-104, 112, 150, 224-227, 369, 388, 458, 477-480, 489, 599, 605, 637, 655, 707
R/tt_compare_tables.R           72       4  94.44%   51, 174, 249, 253
R/tt_compatibility.R           574      70  87.80%   22, 149-150, 193, 198, 329-330, 334-337, 343, 347, 531, 585-588, 625-627, 665, 698, 718, 738-741, 751-754, 799, 816-820, 826-829, 903, 930-933, 942, 1004, 1012, 1023-1026, 1137, 1144, 1172-1186, 1217-1218
R/tt_dotabulation.R           1323     130  90.17%   60, 255, 260, 262, 311, 336, 340-343, 376-379, 402, 435-438, 466-469, 596-597, 665, 852-856, 942, 946, 974-977, 987, 1007-1011, 1018-1021, 1222-1251, 1318, 1322, 1353, 1457-1460, 1675-1683, 1956-1965, 1976-1978, 2063-2066, 2077, 2082, 2087-2088, 2090, 2101, 2106, 2129, 2215-2234
R/tt_export.R                   13       1  92.31%   45
R/tt_from_df.R                  15       0  100.00%
R/tt_paginate.R                535      40  92.52%   74, 122-131, 242, 341-342, 494, 629-632, 653-657, 802-805, 856-863, 940, 943, 961, 968, 971
R/tt_pos_and_access.R          656      32  95.12%   76, 78-80, 105, 166, 262, 329, 512, 516, 724, 726, 734, 740, 754, 764-767, 990, 1007-1010, 1037, 1096-1097, 1110, 1346-1347, 1373-1376, 1658, 1733
R/tt_showmethods.R             166      24  85.54%   47, 63, 98-120, 230, 256, 265-270, 275, 278-282, 285, 374-375
R/tt_sort.R                    115       6  94.78%   50, 289-292, 300
R/tt_toString.R                439      24  94.53%   125, 355, 377, 390, 400, 406, 409, 415-425, 518, 619, 826-851
R/utils.R                       34       7  79.41%   56, 169-174
R/validate_table_struct.R       84      10  88.10%   80-84, 93-94, 140, 149-150
R/Viewer.R                      61       9  85.25%   46, 50, 60-64, 84, 118
TOTAL                         9191     867  90.57%

Diff against main

Filename                  Stmts    Miss  Cover
----------------------  -------  ------  -------
R/00tabletrees.R             +6      +2  -0.17%
R/colby_constructors.R      -83     -10  +0.96%
R/nesting_impl.R           +229     +28  +87.77%
R/tree_accessors.R          -24      -2  -0.05%
R/tt_dotabulation.R         +57     +33  -2.16%
R/tt_pos_and_access.R         0      -1  +0.15%
R/tt_showmethods.R           +4      +3  -1.49%
TOTAL                      +189     +53  -0.39%

Results for commit: 7814d28

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Unit Tests Summary

    1 files     32 suites   2m 3s ⏱️
  261 tests   261 ✅ 0 💤 0 ❌
1 972 runs  1 972 ✅ 0 💤 0 ❌

Results for commit 7814d28.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
nesting 👶 $+8.63$ $+28$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
Tabulation framework 💀 $0.67$ $-0.67$ deeply_nested_and_uneven_column_layouts_work
nesting 👶 $+0.40$ at_sibling_creates_intermediate_row_nesting
nesting 👶 $+0.28$ at_sibling_shows_dynamic_cut_split_labels
nesting 👶 $+0.77$ deeply_nested_and_uneven_column_layouts_work
nesting 👶 $+7.09$ intermediate_nesting_works_correctly
nesting 👶 $+0.09$ split_under_analyze

Results for commit d7f2423

♻️ This comment has been updated with latest results.

Copilot AI and others added 2 commits August 25, 2026 06:00
Co-authored-by: shajoezhu <3692541+shajoezhu@users.noreply.github.com>
Co-authored-by: shajoezhu <3692541+shajoezhu@users.noreply.github.com>
Comment thread R/nesting_impl.R Outdated
@munoztd0
munoztd0 requested review from Melkiades and munoztd0 August 25, 2026 15:11

@munoztd0 munoztd0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finished last tweaks and adress comments

@shajoezhu

Copy link
Copy Markdown
Collaborator

@gmbecker @munoztd0 can we test this in the scda.test please

@munoztd0

Copy link
Copy Markdown
Contributor

@gmbecker @munoztd0 can we test this in the scda.test please

Of course just launched the PR -> insightsengineering/scda.test#245
But putting this PR in draft because waiting for @gmbecker vignette

@munoztd0
munoztd0 marked this pull request as draft August 25, 2026 15:35

@Melkiades Melkiades left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, the at_sibling feature does what #1095 asked and the happy path is solid. Verified it builds correctly and the moved column-nesting test still checks out. A couple of real bugs on the error paths though, plus some cleanup. Comments inline.

Comment thread R/nesting_impl.R
sib_matches <- is.null(at_sibling) || at_sibling == first_spl_name(lastel)
if (endontree && sib_matches) {
splvec[[branch_pos]] <- SplitVectorTree(lst = c(lastel, list(SplitVector(newspl))))
} else if (has_force_pag(lastel)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crashes on the exact case the docs say is unsupported. If at_sibling targets something that was itself placed with at_sibling, lastel is a SplitVectorTree and has_force_pag has no method for that class, so you get an internal dispatch error instead of the informative message.

basic_table() |>
  split_rows_by("STRATA1") |>
  split_rows_by("SEX") |> analyze("AGE") |>
  split_rows_by("RACE", at_sibling = "SEX") |> analyze("AGE") |>
  split_rows_by("BMRKR2", at_sibling = "RACE") |> analyze("AGE") |>
  build_table(ex_adsl)
#> unable to find an inherited method for 'has_force_pag' for signature 'SplitVectorTree'

Needs an up-front guard with the documented error, or a has_force_pag method for SplitVectorTree. Worth a test too.

Comment thread R/nesting_impl.R
splvec[[branch_pos]] <- SplitVectorTree(lst = c(lastel, list(SplitVector(newspl))))
} else if (has_force_pag(lastel)) {
stop(
"at_sibling pointed to a split with forced pagination (page_by = TRUE).",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard isn't actually reached when the target uses page_by = TRUE. Instead of this message you get 'Got a page title prefix for an Elementary Table':

basic_table() |> split_rows_by("STRATA1", page_by = TRUE) |>
  split_rows_by("RACE", at_sibling = "STRATA1") |> analyze("AGE") |>
  build_table(ex_adsl)

Would be good to make the intended error fire, with a test.

Comment thread R/tt_dotabulation.R
alt_df = alt_df,
alt_df_full = alt_df_full,
splvec = splvecii,
name = obj_name(unlist(splvecii, recursive = TRUE)[[1]]), ## XXX I think this is wrong

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These XXX markers are in the tabulation core (name= here, no_outer_tbl = TRUE just below and at 1245). Since this drives the actual table build, can we resolve them or pin the assumption with a test rather than shipping the uncertainty?

Comment thread R/argument_conventions.R
#' to the *split* or *group of sibling analyses*, for `split_rows_by*` and
#' `analyze*` when analyzing more than one variable, respectively. Ignored when
#' analyzing a single variable.
#' @param at_sibling (`charactere(1)` or `NULL`)\cr If non-null, a preceding

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: charactere(1) -> character(1). This leaks into the generated Rd files.

Comment thread R/nesting_impl.R
setMethod(
"split_rows", "ANY",
function(lyt, spl, pos, at_sibling = NULL) {
stop("nope. can't add a row split to that (", class(lyt), "). contact the maintaner.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in the user-facing message: maintaner -> maintainer (also lines 326, 479, 549, and AnalzyeMultiVars in the comment at 453). Spell-check CI may catch these.

Comment thread R/nesting_impl.R

## i <- 1
## found <- numeric()
## while (i <= length(nmlst) && !found) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover commented-out while loop from the old implementation. Can drop it now that the vapply version above replaces it.

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.

5 participants