Skip to content

Commit d3d3aad

Browse files
committed
bug-fix: miss-match rows for n_print
1 parent ea63756 commit d3d3aad

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

R/print_methods.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ but they do not completely overlap.")
254254
top_n <- ceiling(n / 2)
255255
bot_n <- floor(n / 2)
256256

257+
if (bot_n == 0) separator_row_flag = FALSE
258+
257259
row_slice <- if (nr < 2 * n) {
258260
seq_len(nr)
259261
} else {
@@ -295,9 +297,12 @@ but they do not completely overlap.")
295297

296298
sub_seq <- if (nn < 2 * top_n) {
297299
seq_len(nn)
300+
} else if (bot_n == 0){
301+
seq_len(top_n)
298302
} else {
299303
c(seq_len(top_n), (nn - bot_n + 1):nn)
300304
}
305+
301306
out_sub <- out[sub_seq, ]
302307

303308
# Compute the max character width for each column
@@ -351,8 +356,8 @@ but they do not completely overlap.")
351356
)
352357

353358
# print(attributes(out_sub))
354-
355-
out_sub %>% print()
359+
360+
out_sub %>% print(n = ifelse(separator_row_flag, n+1, n), ...)
356361
invisible(x)
357362
}
358363

R/tidyprint_1_utlis.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ ctl_new_rowid_pillar.SE_print_abstraction <- function(controller, x, width, ...)
2929
# message('total_rows=', total_rows)
3030

3131
# Generate row IDs: First n/2 rows, then a separator, then last n/2 rows
32-
if (total_rows > n) {
32+
if (n <= 1) {
33+
rowid <- seq_len(ceiling(n / 2))
34+
} else if (total_rows > n) {
3335
rowid <- c(
3436
seq_len(ceiling(n / 2)), # Top half
35-
NA, # Separator row (will be replaced with `---`)
37+
NA, # Separator row (will be replaced with `---`)
3638
(total_rows - floor(n / 2) + 1):total_rows # Bottom half
3739
)
3840
} else {

0 commit comments

Comments
 (0)