Skip to content

Commit

Permalink
Merge pull request #432 from r-lib/b-distribute-pillars
Browse files Browse the repository at this point in the history
- Fixed some cases for combinations of printed width and `getOption("width")` (#432).
  • Loading branch information
krlmlr committed Dec 30, 2021
2 parents daa7a66 + b9a869e commit fe4570b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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))
})
})

0 comments on commit fe4570b

Please sign in to comment.