From 0c52cf195b3b97669974546732694992d1a3c95b Mon Sep 17 00:00:00 2001 From: Stefano Mangiola Date: Sat, 25 Oct 2025 17:26:37 +1030 Subject: [PATCH] Bump version to 0.99.7 - Update print method parameter from n_print to n - Changed parameter name in print.SummarizedExperiment function for clarity - Updated documentation and examples to reflect the new parameter name - Adjusted internal logic to use the new parameter name consistently - Updated tests to verify functionality with the new parameter name --- DESCRIPTION | 2 +- R/print_methods.R | 30 ++++++++++++++--------------- R/tidyprint_1_utlis.R | 2 +- man/print.SummarizedExperiment.Rd | 8 ++++---- tests/testthat/test-print_methods.R | 4 ++-- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e6f4695..e2b08f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tidyprint Title: Custom Print Methods for SummarizedExperiment -Version: 0.99.6 +Version: 0.99.7 Depends: R (>= 4.4.0) Authors@R: person("Chen", "Zhan", , "chen.zhan@adelaide.edu.au", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-4794-8339")) diff --git a/R/print_methods.R b/R/print_methods.R index 42e87ef..38fc1b7 100644 --- a/R/print_methods.R +++ b/R/print_methods.R @@ -5,8 +5,8 @@ #' the table is truncated. #' #' @param x A \code{SummarizedExperiment} object to print. -#' @param n_print Integer (default \code{10}). Approximate number of rows to show -#' in the display. When the total cells shown are fewer than \code{n_print}, the +#' @param n Integer (default \code{10}). Approximate number of rows to show +#' in the display. When the total cells shown are fewer than \code{n}, the #' full table is printed and the separator row is suppressed. #' @param ... Additional arguments passed to internal printers (currently unused). #' @@ -25,7 +25,7 @@ #' \dontrun{ #' library(tidyprint) #' print(se_airway) # compact tibble display -#' print(se_airway, n_print = 20) # with custom row count +#' print(se_airway, n = 20) # with custom row count #' } #' #' @importClassesFrom SummarizedExperiment SummarizedExperiment @@ -41,37 +41,37 @@ #' @importFrom magrittr `%>%` #' @importFrom dplyr if_else mutate across all_of #' @export -print.SummarizedExperiment <- function(x, n_print = 10, ...) { +print.SummarizedExperiment <- function(x, n = 10, ...) { # SE_print_abstraction - print_tidyprint_1 <- function(x, n = n_print , ...){ + print_tidyprint_1 <- function(x, n_print = n, ...){ onr <- nr <- nrow(x) %>% as.double() onc <- nc <- ncol(x) %>% as.double() - if ( onc > 0 && onr > 0 && n / onc >= onr ) { - n <- onc*onr + if ( onc > 0 && onr > 0 && n_print / onc >= onr ) { + n_print <- onc*onr separator_row_flag = FALSE }else{ separator_row_flag = TRUE } - top_n <- ceiling(n / 2) - bot_n <- floor(n / 2) + top_n <- ceiling(n_print / 2) + bot_n <- floor(n_print / 2) if (bot_n == 0) separator_row_flag = FALSE - row_slice <- if (nr < 2 * n) { + row_slice <- if (nr < 2 * n_print) { seq_len(nr) } else { - c(seq_len(n), (nr - n + 1):nr) + c(seq_len(n_print), (nr - n_print + 1):nr) } - col_slice <- if (nc < 2 * n) { + col_slice <- if (nc < 2 * n_print) { seq_len(nc) } else { - c(seq_len(n), (nc - n + 1):nc) + c(seq_len(n_print), (nc - n_print + 1):nc) } x_ <- x[row_slice, col_slice] @@ -140,7 +140,7 @@ print.SummarizedExperiment <- function(x, n_print = 10, ...) { out_sub = out_sub %>% vctrs::new_data_frame(class=c('SE_print_abstraction', "tbl_df", "tbl", "data.frame")) %>% - add_attr(n, 'n_print') %>% + add_attr(n_print, 'n') %>% add_attr(onc*onr, 'total_rows') %>% add_attr(nrow(x), "number_of_features") %>% add_attr(ncol(x), "number_of_samples") %>% @@ -162,7 +162,7 @@ print.SummarizedExperiment <- function(x, n_print = 10, ...) { # print(attributes(out_sub)) - out_sub %>% print(n = ifelse(separator_row_flag, n+1, n), ...) + out_sub %>% print(n = ifelse(separator_row_flag, n_print+1, n_print), ...) invisible(x) } diff --git a/R/tidyprint_1_utlis.R b/R/tidyprint_1_utlis.R index b0b1bfd..ab54d93 100644 --- a/R/tidyprint_1_utlis.R +++ b/R/tidyprint_1_utlis.R @@ -21,7 +21,7 @@ ctl_new_rowid_pillar.SE_print_abstraction <- function(controller, x, width, ...) # print(controller %>% attributes()) out <- NextMethod() - n = controller |> attr('n_print') + n = controller |> attr('n') total_rows = controller |> attr('total_rows') diff --git a/man/print.SummarizedExperiment.Rd b/man/print.SummarizedExperiment.Rd index 6b06bb9..1bb1979 100644 --- a/man/print.SummarizedExperiment.Rd +++ b/man/print.SummarizedExperiment.Rd @@ -4,13 +4,13 @@ \alias{print.SummarizedExperiment} \title{Print method for SummarizedExperiment with tidyprint styles} \usage{ -\method{print}{SummarizedExperiment}(x, n_print = 10, ...) +\method{print}{SummarizedExperiment}(x, n = 10, ...) } \arguments{ \item{x}{A \code{SummarizedExperiment} object to print.} -\item{n_print}{Integer (default \code{10}). Approximate number of rows to show -in the display. When the total cells shown are fewer than \code{n_print}, the +\item{n}{Integer (default \code{10}). Approximate number of rows to show +in the display. When the total cells shown are fewer than \code{n}, the full table is printed and the separator row is suppressed.} \item{...}{Additional arguments passed to internal printers (currently unused).} @@ -34,7 +34,7 @@ half block of rows. Additional indication of \code{colData} is provided as well. \dontrun{ library(tidyprint) print(se_airway) # compact tibble display - print(se_airway, n_print = 20) # with custom row count + print(se_airway, n = 20) # with custom row count } } diff --git a/tests/testthat/test-print_methods.R b/tests/testthat/test-print_methods.R index 94f3240..4c51152 100644 --- a/tests/testthat/test-print_methods.R +++ b/tests/testthat/test-print_methods.R @@ -13,8 +13,8 @@ test_that("Default print works", { expect_output(print(se_airway), "A SummarizedExperiment-tibble abstraction:") }) -test_that("Print works with n_print", { - expect_output(print(se_airway, n_print = 5), "A SummarizedExperiment-tibble abstraction:") +test_that("Print works with n", { + expect_output(print(se_airway, n = 5), "A SummarizedExperiment-tibble abstraction:") }) # test for message