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

split_into_pages_by_var into paginate_listing can result in different horizontal pagination in different "sections" of the listing #213

Open
gmbecker opened this issue May 20, 2024 · 0 comments
Labels
bug Something isn't working sme

Comments

@gmbecker
Copy link
Collaborator

gmbecker commented May 20, 2024

Usually listings will be paginated with colwidths set. In this case the colwidths will be the same for all pages, even when split_into_pages_by_var is breaking alisting up into a list prior to pagination.

In the corner case they are not, however, we can get listings that have different column widths for the different "pagination sections" it is split into. In extreme cases this can result in column pagination being entirely different between sections of the listing:

mtcars2 <- mtcars

carspl <- strsplit(row.names(mtcars2), " ")
mtcars2$brand <- sapply(carspl, function(x) x[1])
mtcars2$model <- sapply(carspl, function(x) paste(x[-1], collapse = " "))

mtcars3 <- subset(mtcars2, brand %in% c("Dodge", "AMC", "Merc", "Datsun"))

lsting <- as_listing(mtcars3, key_cols = c("am", "cyl"),
                     disp_cols = c("model", "hp", "gear", "disp"))

topag <- split_into_pages_by_var(lsting, "brand")


res <- paginate_listing(topag, cpp = 26)

gives us

--- Page 1/10 ---
brand: Merc

———————————————————————
am   cyl   model    hp 
———————————————————————
0     4     240D    62 
            230     95 
      6     280     123
            280C    123
      8    450SE    180
           450SL    180
           450SLC   180

--- Page 2/10 ---
brand: Merc

———————————————————————
am   cyl   gear   disp 
———————————————————————
0     4     4     146.7
            4     140.8
      6     4     167.6
            4     167.6
      8     3     275.8
            3     275.8
            3     275.8

--- Page 3/10 ---
brand: Dodge

—————————————————————
am   cyl     model   
—————————————————————
0     8    Challenger

--- Page 4/10 ---
brand: Dodge

—————————————————————
am   cyl   hp    gear
—————————————————————
0     8    150    3  

--- Page 5/10 ---
brand: Dodge

———————————————
am   cyl   disp
———————————————
0     8    318 

--- Page 6/10 ---
brand: AMC

——————————————————
am   cyl    model 
——————————————————
0     8    Javelin

--- Page 7/10 ---
brand: AMC

—————————————————————
am   cyl   hp    gear
—————————————————————
0     8    150    3  

--- Page 8/10 ---
brand: AMC

———————————————
am   cyl   disp
———————————————
0     8    304 

--- Page 9/10 ---
brand: Datsun

—————————————————————
am   cyl   model   hp
—————————————————————
1     4     710    93

--- Page 10/10 ---
brand: Datsun

——————————————————————
am   cyl   gear   disp
——————————————————————
1     4     4     108 

The Merc and Datsun sections are each separated into two pages, while the Dodge and AMC sections are separated into three, despite them being parts of the same listing.

Breaking the listing into parts after pagination begins (ie after paginate_listing is called) would not have this issue because the overall colwidths could be calculated before the split and thus apply to all parts. That is the intention of allowing packages to define do_forced_paginate, which does exactly this (see the page_by behavior for rtables).

@gmbecker gmbecker added the bug Something isn't working label May 20, 2024
@Melkiades Melkiades added the sme label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sme
Projects
None yet
Development

No branches or pull requests

2 participants