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

Fix distribute_pillars_rev() #432

Merged
merged 1 commit into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions R/multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ distribute_pillars_rev <- function(widths, tier_widths) {
tier <- length(tier_widths) + 1L - ret$tier
ret$tier <- tier

splits <- unname(split(seq_along(tier), tier))
tier_widths <- tier_widths[seq_along(splits)]
splits <- split(seq_along(tier), tier)
tier_widths <- tier_widths[stats::na.omit(unique(tier))]

new_offset_after <- unlist(map2(splits, tier_widths, function(.x, .y) {
new_offset_after <- unlist(map2(unname(splits), tier_widths, function(.x, .y) {
new_offset_after <- cumsum(ret$width[.x] + 1)
new_offset_after - max(new_offset_after) + .y
}))
Expand Down
18 changes: 15 additions & 3 deletions tests/testthat/_snaps/multi.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@
id tier width offset_after
1 1 2 5 5
2 2 3 5 5
Code
distribute_pillars(c(5, 5), c(8, 8, 2))
Output
id tier width offset_after
1 1 1 5 5
2 2 2 5 5

# distribute_pillars_rev()

Expand Down Expand Up @@ -188,9 +194,9 @@
distribute_pillars_rev(3:5, 8:10)
Output
id tier width offset_after
1 1 2 3 8
2 2 3 4 3
3 3 3 5 9
1 1 2 3 9
2 2 3 4 4
3 3 3 5 10
Code
distribute_pillars_rev(5:3, 9:8)
Output
Expand All @@ -204,4 +210,10 @@
id tier width offset_after
1 1 1 5 8
2 2 2 5 8
Code
distribute_pillars_rev(c(5, 5), c(2, 8, 8))
Output
id tier width offset_after
1 1 2 5 8
2 2 3 5 8

2 changes: 2 additions & 0 deletions tests/testthat/test-multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test_that("distribute_pillars()", {
distribute_pillars(3:5, 8:10)
distribute_pillars(5:3, 9:8)
distribute_pillars(c(5, 5), c(2, 8, 8))
distribute_pillars(c(5, 5), c(8, 8, 2))
})
})

Expand All @@ -36,5 +37,6 @@ test_that("distribute_pillars_rev()", {
distribute_pillars_rev(3:5, 8:10)
distribute_pillars_rev(5:3, 9:8)
distribute_pillars_rev(c(5, 5), c(8, 8, 2))
distribute_pillars_rev(c(5, 5), c(2, 8, 8))
})
})