Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

761 better getter seeters@221 fix separator div@main #782

Merged
merged 35 commits into from
Nov 24, 2023

Conversation

Melkiades
Copy link
Contributor

@Melkiades Melkiades commented Nov 13, 2023

Fixes #761 #762. Somehow close to #509

basic_table(header_section_div = " ") %>%
    split_cols_by("ARM") %>%
    split_rows_by("SEX", split_fun = drop_split_levels) %>%
    analyze("AGE") %>%
    build_table(DM)

makes

         A: Drug X   B: Placebo   C: Combination
————————————————————————————————————————————————
                                                
F                                               
  Mean     33.71       33.84          34.89     
M                                               
  Mean     36.55       32.10          34.28     

but if there are multiple analyze it does not print anything. These options differ, but it should print something in those cases.

@Melkiades Melkiades added bug tests Something they are concerned to sme labels Nov 13, 2023
Copy link
Contributor

github-actions bot commented Nov 13, 2023

badge

Code Coverage Summary

Filename                     Stmts    Miss  Cover    Missing
-------------------------  -------  ------  -------  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
R/00tabletrees.R               744      62  91.67%   21, 102, 105, 412, 496-497, 500, 656, 757, 849-850, 951, 953-954, 977-980, 1002, 1114-1117, 1212-1217, 1365, 1462-1465, 1529-1532, 1568-1571, 1577-1582, 1632, 1639, 1739, 1852, 1866, 1869-1872, 1875-1878, 1906, 1937-1938
R/as_html.R                    161      25  84.47%   5-10, 74, 131-136, 141-146, 161-165, 253
R/colby_constructors.R         557      20  96.41%   71, 123, 181-184, 244-247, 387, 404, 1213, 1304, 1465, 1503, 1525, 1549, 1570, 1726
R/compare_rtables.R             83      17  79.52%   93-96, 99-102, 115-118, 137, 157-158, 189, 194
R/format_rcell.R                12       0  100.00%
R/indent.R                      13       2  84.62%   39-40
R/index_footnotes.R             66       0  100.00%
R/make_split_fun.R             119      23  80.67%   22-25, 51-54, 57-60, 115, 119, 280, 283-286, 291-294, 313, 412
R/make_subset_expr.R           136      14  89.71%   34-48, 126-133, 168, 250, 266, 274
R/simple_analysis.R              5       1  80.00%   55
R/split_funs.R                 505      66  86.93%   143, 148, 154-159, 164, 181-185, 366-371, 388-393, 474, 526, 544-547, 564, 631, 641-642, 644, 658, 702, 727, 903, 910, 936-939, 950-951, 953, 955, 1126-1128, 1142-1146, 1210-1213, 1276-1279
R/summary.R                    215      24  88.84%   38, 85, 192, 200, 271-276, 287-288, 307-308, 418, 465-481, 516, 549
R/tree_accessors.R             946     102  89.22%   109, 251, 269, 292, 330, 344, 360, 465, 492-493, 774-779, 907, 925, 949, 999, 1054-1055, 1094, 1127, 1163-1167, 1220, 1295-1299, 1317-1327, 1396, 1501-1504, 1529, 1549-1550, 1559, 1600, 1618-1622, 1643-1647, 1726, 1768, 1872, 1976, 1989, 2002, 2016, 2024, 2033-2037, 2379, 2737, 2850, 2883-2905, 2994-3001, 3156, 3229-3234, 3443-3444, 3451, 3454-3457, 3461, 3512, 3546, 3571-3595
R/tt_afun_utils.R              411      32  92.21%   50, 164, 171, 181-194, 260, 271-272, 504, 512-515, 597-601, 622, 637-639
R/tt_compare_tables.R           70       4  94.29%   56, 178, 257, 261
R/tt_compatibility.R           510      56  89.02%   19, 142-143, 192, 197, 332-333, 337-340, 346, 350, 398, 520, 568, 601, 621, 654-657, 701, 718-722, 809, 837-840, 849, 912, 920, 931-934, 1044, 1051, 1080-1094, 1125-1126
R/tt_dotabulation.R           1117      96  91.41%   54, 252, 257, 259, 310, 334, 338-341, 373-376, 399, 434-437, 465-468, 565, 702-706, 756, 760, 789-792, 802, 822-826, 833-836, 1095, 1099, 1130, 1243-1246, 1442-1450, 1591, 1675-1684, 1764-1767, 1778, 1783, 1788-1789, 1791, 1802, 1807, 1830, 1925-1944
R/tt_export.R                  472      44  90.68%   48, 65, 105-109, 142, 181-185, 249-262, 365-368, 383, 711, 720, 745-749, 916-919, 922, 953, 959
R/tt_from_df.R                   9       0  100.00%
R/tt_paginate.R                440      37  91.59%   45, 70, 107-115, 396, 518-521, 541-545, 695-698, 748-755, 824, 827, 837, 844, 847
R/tt_pos_and_access.R          571      43  92.47%   77, 79-81, 106, 166, 212-216, 262, 514, 516, 524, 530, 544, 554-557, 739, 750-754, 759-762, 789, 842-843, 855, 1021-1022, 1080-1108, 1388, 1465
R/tt_showmethods.R             144      21  85.42%   60, 97-120, 183, 209, 218, 226, 229-233, 326-327
R/tt_sort.R                     88       5  94.32%   223-226, 234
R/tt_toString.R                394      25  93.65%   118, 309, 358, 373, 383, 390, 393, 399-409, 497, 562, 568, 803-829
R/utils.R                       23       0  100.00%
R/validate_table_struct.R       84      12  85.71%   79-83, 92-93, 140, 150-151, 204-205
R/Viewer.R                      61       9  85.25%   47, 51, 61-65, 85, 119
TOTAL                         7956     740  90.70%

Diff against main

Filename                     Stmts    Miss  Cover
-------------------------  -------  ------  --------
R/00tabletrees.R              +120     +21  -1.76%
R/as_html.R                    +73     +18  -7.57%
R/colby_constructors.R         +75      +3  -0.06%
R/compare_rtables.R             +5      +6  -6.38%
R/index_footnotes.R            +16       0  +100.00%
R/make_split_fun.R            +119     +23  +80.67%
R/make_subset_expr.R           +30      +2  +1.03%
R/split_funs.R                 +84     +11  -0.01%
R/summary.R                    +32      +8  -2.42%
R/tree_accessors.R            +153     +34  -2.21%
R/tt_afun_utils.R              +66      +7  -0.54%
R/tt_compare_tables.R           +5       0  +0.44%
R/tt_compatibility.R           +97      +6  +1.13%
R/tt_dotabulation.R           +380     +52  -2.62%
R/tt_export.R                 +243     -29  +22.56%
R/tt_paginate.R                +57     +22  -4.49%
R/tt_pos_and_access.R          +51      +6  -0.42%
R/tt_showmethods.R             +23       0  +2.77%
R/tt_sort.R                     +7      -1  +1.73%
R/tt_toString.R                +89      +3  +0.87%
R/utils.R                      +12      -1  +9.09%
R/validate_table_struct.R      +84     +12  +85.71%
R/Viewer.R                      +5       0  +1.32%
TOTAL                        +1826    +203  -0.54%

Results for commit: 877745a

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Nov 13, 2023

Unit Tests Summary

       1 files       24 suites   1m 26s ⏱️
   194 tests    194 ✔️ 0 💤 0
1 488 runs  1 488 ✔️ 0 💤 0

Results for commit 877745a.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@edelarua edelarua left a comment

Choose a reason for hiding this comment

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

Great job! I think this would cover a wide variety of use cases if people want to use section dividers, but is there any way to produce this table:

                 all obs
————————————————————————
A: Drug X               
  A                     
    Mean          32.53 
  B                     
    Mean          35.46 
  C                     
    Mean          36.34 
------------------------
B: Placebo              
  A                     
    Mean          32.30 
  B                     
    Mean          32.42 
  C                     
    Mean          34.45 
------------------------
C: Combination          
  A                     
    Mean          35.76 
  B                     
    Mean          34.39 
  C                     
    Mean          33.54 

I feel like this would be the most typical implementation by basic users.

NEWS.md Outdated Show resolved Hide resolved
@@ -647,7 +646,8 @@ AnalyzeVarSplit <- function(var,
extra_args = list(),
indent_mod = 0L,
label_pos = "default",
cvar = "") {
cvar = "",
section_div = NA_character_) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it is possible to do it also in analyze

contdf <- make_row_df(content_table(tt),
ct_tt <- content_table(tt)
cind <- indent + indent_mod(ct_tt)
trailing_section_div(ct_tt) <- trailing_section_div(tt_labelrow(tt))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As section_div setter is based solely on labelrow and datarow, this fixes the contentRow case

return(grepl(regex, element))
}

test_structure_with_a_getter <- function(tbl, getter, val_per_lev) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

helper function to check we are doing the right thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to check vs structure

@Melkiades
Copy link
Contributor Author

Great job! I think this would cover a wide variety of use cases if people want to use section dividers, but is there any way to produce this table:

                 all obs
————————————————————————
A: Drug X               
  A                     
    Mean          32.53 
  B                     
    Mean          35.46 
  C                     
    Mean          36.34 
------------------------
B: Placebo              
  A                     
    Mean          32.30 
  B                     
    Mean          32.42 
  C                     
    Mean          34.45 
------------------------
C: Combination          
  A                     
    Mean          35.76 
  B                     
    Mean          34.39 
  C                     
    Mean          33.54 

I feel like this would be the most typical implementation by basic users.

basic_table() %>% 
  split_rows_by("ARM", section_div = "-") %>% 
  split_rows_by("STRATA1") %>% 
  analyze("BMRKR1") %>% 
  build_table(DM)

Can you please see if section_div getter and setter work fine for you? :)

…f github.com:Roche/rtables into 761_better_getter_seeters@221_fix_separator_div@main
@edelarua
Copy link
Contributor

Hi Davide,

Thanks for the example code - I think my test code was getting too complicated and I missed that somehow.

A couple of questions/comments on the getters/setters:

I'll use this table code for examples:

t <- basic_table() %>% 
    split_rows_by("ARM") %>% 
    split_rows_by("STRATA1") %>% 
    analyze("BMRKR1") %>% 
    build_table(DM)
                 all obs
————————————————————————
A: Drug X               
  A                     
    Mean          5.90  
  B                     
    Mean          5.55  
  C                     
    Mean          5.94  
B: Placebo              
  A                     
    Mean          6.01  
  B                     
    Mean          5.86  
  C                     
    Mean          6.53  
C: Combination          
  A                     
    Mean          5.95  
  B                     
    Mean          6.32  
  C                     
    Mean          4.91  
  1. I'm not sure if this is a lot more difficult to do (in which case you can ignore me :) ) but I think the most logical way to implement section_div would be to go from the outermost to innermost split dividers. So if the user gave only one value in the example table t above (i.e. section_div(t) <- "~"), the section divider would be applied between arm splits, if they gave two (i.e. section_div(t) <- c("~", ".")) the first would apply to the arm split, the second would apply to the STRATA1 split, etc.
    In the current implementation, you have it requiring a vector of length nrow(t) which I feel might be a bit overwhelming to the average user. But again, it's working great as is for me, this is just an alternative idea - I'm not sure how specifically a typical user would want to edit the section dividers, or if they need them in weird places :).

  2. Not sure if you meant for me to test header_section_div but it's currently adding a line below what I would expect to be the header section div (i.e. the line separating the header contents from the body contents).

E.g.

header_section_div(t) <- "~"
t
                 all obs
————————————————————————
~~~~~~~~~~~~~~~~~~~~~~~~
A: Drug X               
  A                     
    Mean          5.90  
  B                     
    Mean          5.55  
  C                     
    Mean          5.94  
B: Placebo              
  A                     
    Mean          6.01  
  B                     
    Mean          5.86  
  C                     
    Mean          6.53  
C: Combination          
  A                     
    Mean          5.95  
  B                     
    Mean          6.32  
  C                     
    Mean          4.91  

Other than that the getters/setters are all working correctly for me!

@Melkiades
Copy link
Contributor Author

Thanks for trying it out Emily!

  1. It makes sense, but I needed to get the row-wise implementation first to establish exactly where everything should be to set/get the whole tree divisors. It will take a bit of work, but I can add separators for splits only and one value only for those splits.
  2. I think we need another variable for Add "top_level_div" to allow section divs between top-level subtables #509 as the one I implemented was asked by Chenkai and others some times ago and it was to add a space between header line and table body

@Melkiades
Copy link
Contributor Author

@edelarua 1. Is done. I added as default that if you add only one value, you have it for all levels. Let me know if only the first split/section should have it. You can do that anyway like this: section_div(tbl) <- c("a", NA_character_).

  1. as mentioned, header_section_div is another thing, i.e. the need to have a " " before the start of the table. There is no other way to add this empty line otherwise. For the table divisor, instead, we can still use the section_div and put it where we want. Doing it with another section div parameter seems a bit difficult, also considering the fact that the print collapses it and the realization could be redundant (and you need to understand much better how tables works to attempt this thing specifically)

Copy link
Contributor

@edelarua edelarua left a comment

Choose a reason for hiding this comment

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

The new behaviour is great, thanks for implementing that!! Everything seems to be working as expected for me, and the warning messages are very informative. I reviewed the documentation as well and just added some minor suggestions for grammar fixes/typos.

Excellent work!!! :)

R/tree_accessors.R Outdated Show resolved Hide resolved
R/tree_accessors.R Outdated Show resolved Hide resolved
R/tree_accessors.R Outdated Show resolved Hide resolved
R/tree_accessors.R Outdated Show resolved Hide resolved
R/tree_accessors.R Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
@edelarua edelarua linked an issue Nov 23, 2023 that may be closed by this pull request
Melkiades and others added 6 commits November 24, 2023 09:16
Co-authored-by: Emily de la Rua <[email protected]>
Signed-off-by: Davide Garolini <[email protected]>
Co-authored-by: Emily de la Rua <[email protected]>
Signed-off-by: Davide Garolini <[email protected]>
Co-authored-by: Emily de la Rua <[email protected]>
Signed-off-by: Davide Garolini <[email protected]>
Co-authored-by: Emily de la Rua <[email protected]>
Signed-off-by: Davide Garolini <[email protected]>
Co-authored-by: Emily de la Rua <[email protected]>
Signed-off-by: Davide Garolini <[email protected]>
@Melkiades Melkiades merged commit 9b4409e into main Nov 24, 2023
17 checks passed
@Melkiades Melkiades deleted the 761_better_getter_seeters@221_fix_separator_div@main branch November 24, 2023 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug sme tests Something they are concerned to
Projects
None yet
Development

Successfully merging this pull request may close these issues.

what is section_div in analyze? Add getter/setter for section dividers
3 participants