Skip to content

Commit 252b743

Browse files
committed
bug fix for very small se data
1 parent 266f818 commit 252b743

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

R/print_methods.R

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,27 @@ but they do not completely overlap.")
191191
} else if (design == "tidyprint_1"){
192192

193193
print_tidyprint_1 <- function(x, n = n_print , ...){
194+
195+
onr <- nr <- nrow(x)
196+
onc <- nc <- ncol(x)
197+
198+
if (n >= onc*onr) {
199+
n = onc*onr
200+
separator_row_flag = F
201+
}else{
202+
separator_row_flag = T
203+
}
194204

195205
top_n <- ceiling(n / 2)
196206
bot_n <- floor(n / 2)
197-
onr <- nr <- nrow(x)
207+
198208
row_slice <- if (nr < 2 * n) {
199209
seq_len(nr)
200210
} else {
201211
c(seq_len(n), (nr - n + 1):nr)
202212
}
203213

204-
onc <- nc <- ncol(x)
214+
205215
col_slice <- if (nc < 2 * n) {
206216
seq_len(nc)
207217
} else {
@@ -240,26 +250,29 @@ but they do not completely overlap.")
240250
c(seq_len(top_n), (nn - bot_n + 1):nn)
241251
}
242252
out_sub <- out[sub_seq, ]
243-
253+
244254
# Compute the max character width for each column
245255
separator_row <- sapply(out_sub %>% colnames(), function(col) {
246256
max_width <- max(nchar(as.character(col)), na.rm = TRUE) # Get max width in the column
247257
paste(rep("-", max_width), collapse = "") # Generate a separator of the same length
248258
})
249259

250-
# Modify the entire tibble to include a separator row across all columns
251-
## temporalily convert factor cols to char
252-
fct_col = map(out_sub, is.factor) %>% keep(~{.x == T}) %>% names
253-
if (length(fct_col)) out_sub[, fct_col] = out_sub[, fct_col] %>% mutate(across(all_of(fct_col), as.character))
254-
255-
256-
out_sub <- suppressWarnings(rbind(
257-
out_sub[seq_len(top_n),],
258-
as.list(separator_row), # Adaptive separator row
259-
out_sub[(top_n+1):nrow(out_sub), ]
260-
))
261-
## reverse to factor cols
262-
if (length(fct_col)) out_sub[, fct_col] = out_sub[, fct_col] %>% mutate(across(all_of(fct_col), as.factor))
260+
if (separator_row_flag){
261+
262+
# Modify the entire tibble to include a separator row across all columns
263+
## temporalily convert factor cols to char
264+
fct_col = map(out_sub, is.factor) %>% keep(~{.x == T}) %>% names
265+
if (length(fct_col)) out_sub[, fct_col] = out_sub[, fct_col] %>% mutate(across(all_of(fct_col), as.character))
266+
267+
268+
out_sub <- suppressWarnings(rbind(
269+
out_sub[seq_len(top_n),],
270+
as.list(separator_row), # Adaptive separator row
271+
out_sub[(top_n+1):nrow(out_sub), ]
272+
))
273+
## reverse to factor cols
274+
if (length(fct_col)) out_sub[, fct_col] = out_sub[, fct_col] %>% mutate(across(all_of(fct_col), as.factor))
275+
}
263276

264277
# attr(out_sub, "n") <- n
265278
# attr(out_sub, "total_rows") <- x %>% dim %>% {(.)[1] * (.)[2]}

0 commit comments

Comments
 (0)