diff --git a/DESCRIPTION b/DESCRIPTION index 8c06810..e2b08f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tidyprint Title: Custom Print Methods for SummarizedExperiment -Version: 0.99.5 +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")) @@ -30,7 +30,7 @@ Imports: fansi, pkgconfig Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Suggests: knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index ec1bc1d..54d9056 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,6 +20,7 @@ importFrom(SummarizedExperiment,rowRanges) importFrom(cli,col_br_black) importFrom(cli,col_br_blue) importFrom(dplyr,across) +importFrom(dplyr,all_of) importFrom(dplyr,full_join) importFrom(dplyr,if_else) importFrom(dplyr,left_join) diff --git a/R/print_methods.R b/R/print_methods.R index 7411eef..a7e23d4 100644 --- a/R/print_methods.R +++ b/R/print_methods.R @@ -1,34 +1,18 @@ #' Print method for SummarizedExperiment with tidyprint styles #' -#' Provides alternative console displays for a \link[SummarizedExperiment]{SummarizedExperiment} -#' object. The default shows the standard Bioconductor summary. The -#' `"tidyprint_1"` design prints a compact tibble-like abstraction that -#' preserves assay values and key covariates with a separator band when +#' Provides a compact tibble-like display for a \link[SummarizedExperiment]{SummarizedExperiment} +#' object that preserves assay values and key covariates with a separator band when #' the table is truncated. #' #' @param x A \code{SummarizedExperiment} object to print. -#' @param design Either a character string or integer selecting the print style. -#' Character choices are: -#' \itemize{ -#' \item \code{"SummarizedExperiment"} — standard Bioconductor summary. -#' \item \code{"tidyprint_1"} — tidyprint tibble abstraction (top/bottom slices, -#' assays | colData | rowData blocks, with an adaptive separator row). -#' } -#' Numeric shortcuts are mapped as: -#' \itemize{ -#' \item \code{1} \eqn{\to} \code{"SummarizedExperiment"} -#' \item \code{2} \eqn{\to} \code{"tidyprint_1"} -#' } -#' @param n_print Integer (default \code{10}). Approximate number of rows to show -#' in the \code{"tidyprint_1"} display. When the total cells shown are fewer -#' than \code{n_print}, the full table is printed and the separator row is -#' suppressed. +#' @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). #' #' @details -#' The \code{"tidyprint_1"} design constructs a tibble abstraction for SummarizedExperiment -#' data with columns: -#' \code{.feature}, \code{.sample}, assay columns, a vertical separator \code{"|"}, +#' This method constructs a tibble abstraction for SummarizedExperiment data with +#' columns: \code{.feature}, \code{.sample}, assay columns, a vertical separator \code{"|"}, #' followed by selected \code{colData} and \code{rowData} fields. When the output #' is truncated, an adaptive dash-only separator row is inserted after the first #' half block of rows. Additional indication of \code{colData} is provided as well. @@ -40,9 +24,8 @@ #' @examples #' \dontrun{ #' library(tidyprint) -#' print(se_airway) # default -#' print(se_airway, design = "tidyprint_1") # tidyprint abstraction -#' print(se_airway, design = 2) # numeric alias for "tidyprint_1" +#' print(se_airway) # compact tibble display +#' print(se_airway, n = 20) # with custom row count #' } #' #' @importClassesFrom SummarizedExperiment SummarizedExperiment @@ -56,318 +39,115 @@ #' @importFrom purrr map_chr keep #' @importFrom stringr str_replace #' @importFrom magrittr `%>%` -#' @importFrom dplyr if_else mutate across +#' @importFrom dplyr if_else mutate across all_of #' @export -print.SummarizedExperiment <- function(x, design = 2, n_print = 10, ...) { +print.SummarizedExperiment <- function(x, n = 10, ...) { - # Match the user-supplied design argument to one of the valid choices: - if (is.numeric(design)) { - # Allowed numeric -> corresponding design - design_map <- c("SummarizedExperiment", "tidyprint_1", "tidySummarizedExperiment", "plyxp") - - # Validate numeric input - if (!design %in% seq_len(4)) { - stop("Invalid numeric design argument. Choose 1 or 2.") - } - design <- design_map[design] + # SE_print_abstraction + onr <- nr <- nrow(x) %>% as.double() + onc <- nc <- ncol(x) %>% as.double() + + if ( onc > 0 && onr > 0 && n / onc >= onr ) { + n <- onc*onr + separator_row_flag = FALSE + }else{ + separator_row_flag = TRUE } - design <- match.arg(design, c("SummarizedExperiment", "tidyprint_1", "tidySummarizedExperiment", "plyxp")) + top_n <- ceiling(n / 2) + bot_n <- floor(n / 2) - - if (!inherits(x, "SummarizedExperiment")) { - stop("The object provided is not a SummarizedExperiment.") + if (bot_n == 0) separator_row_flag = FALSE + + row_slice <- if (nr < 2 * n) { + seq_len(nr) + } else { + c(seq_len(n), (nr - n + 1):nr) } - # --- 1) SUMMARIZED EXPERIMENT (DEFAULT) --- - if (design == "SummarizedExperiment") { - - print_summary_summarized_experiment <- function(object) { - cat("class:", class(object), "\n") - cat("dim:", dim(object), "\n") - - expt <- names(metadata(object)) - if (is.null(expt)) expt <- character(length(metadata(object))) - coolcat("metadata(%d): %s\n", expt) - - nms <- assayNames(object) - if (is.null(nms)) nms <- character(length(assays(object, withDimnames = FALSE))) - coolcat("assays(%d): %s\n", nms) - - rownames <- rownames(object) - if (!is.null(rownames)) coolcat("rownames(%d): %s\n", rownames) - else cat("rownames: NULL\n") - - coolcat("rowData names(%d): %s\n", names(rowData(object, use.names = FALSE))) - - colnames <- colnames(object) - if (!is.null(colnames)) coolcat("colnames(%d): %s\n", colnames) - else cat("colnames: NULL\n") - - coolcat("colData names(%d): %s\n", names(colData(object))) - } - - print_summary_summarized_experiment(x) - - # --- 2) TIDY SUMMARIZED EXPERIMENT PRINTING --- - } else if (design == "tidySummarizedExperiment") { - - print_tidy_summarized_experiment <- function(x) { - # Fix NOTEs - . <- NULL - - # Stop if any column or row names are duplicated - if (check_if_any_dimnames_duplicated(x, dim = "cols")) { - stop("tidySummarizedExperiment says: some column names are duplicated") - } - if (check_if_any_dimnames_duplicated(x, dim = "rows")) { - stop("tidySummarizedExperiment says: some row names are duplicated") - } - - # Stop if column names of assays do not overlap - if (check_if_assays_are_NOT_overlapped(x, dim = "cols")) { - stop("tidySummarizedExperiment says: the assays in your SummarizedExperiment have column names, -but they do not completely overlap.") - } - if (check_if_assays_are_NOT_overlapped(x, dim = "rows")) { - stop("tidySummarizedExperiment says: the assays in your SummarizedExperiment have row names, -but they do not completely overlap.") - } - - # Reorder assays before printing - x <- order_assays_internally_to_be_consistent(x) - - tmp_x <- x - if (nrow(tmp_x) > 30) { - tmp_x <- tmp_x[seq_len(min(50, nrow(x))), min(1, ncol(x)), drop = FALSE] - } else if (ncol(tmp_x) == 0) { - tmp_x <- tmp_x - } else { - tmp_x <- tmp_x[, seq_len(min(20, ncol(x))), drop = FALSE] - } - my_tibble <- tmp_x %>% as_tibble() - - my_tibble |> - vctrs::new_data_frame(class=c("tidySummarizedExperiment", "tbl")) %>% - add_attr(nrow(x), "number_of_features") %>% - add_attr(ncol(x), "number_of_samples") %>% - add_attr(assays(x) %>% names, "assay_names") %>% - add_attr( - sprintf( - "%s %s %s", - x %>% dim %>% {(.)[1] * (.)[2]} %>% - format(format="f", big.mark=",", digits=1), - cli::symbol$times, - ncol(my_tibble) - ) %>% - setNames("A SummarizedExperiment-tibble abstraction"), - "named_header" - ) %>% - print() - invisible(x) - } - - print_tidy_summarized_experiment(x) - - # --- 3) plyxp-STYLE PRINTING --- - } else if (design == "plyxp"){ - - print_plyxp_summarized_experiment <- function(x, n = n_print , ...) { - top_n <- ceiling(n / 2) - bot_n <- floor(n / 2) - onr <- nr <- nrow(x) - row_slice <- if (nr < 2 * n) { - seq_len(nr) - } else { - c(seq_len(n), (nr - n + 1):nr) - } - - onc <- nc <- ncol(x) - col_slice <- if (nc < 2 * n) { - seq_len(nc) - } else { - c(seq_len(n), (nc - n + 1):nc) - } - - x_ <- x[row_slice, col_slice] - nr <- nrow(x_) - nc <- ncol(x_) - .features <- rownames(x_) %||% seq_len(onr)[row_slice] - .samples <- colnames(x_) %||% seq_len(onc)[col_slice] - - assays_ <- purrr::map(assays(x_), as_vec) - row_ <- purrr::map(rowData(x_), vec_rep, times = nc) |> purrr::map(maybe_phantom) - col_ <- purrr::map(colData(x_), vec_rep_each, times = nr) |> purrr::map(maybe_phantom) - - nn <- nc * nr - out <- c( - list( - .features = vctrs::vec_rep(.features, times = nc), - .samples = vctrs::vec_rep_each(.samples, times = nr) - ), - list(`|` = sep_(nn)), - assays_, - list(`|` = sep_(nn)), - row_, - list(`|` = sep_(nn)), - col_ - ) - attr(out, "row.names") <- c(NA_integer_, -nn) - class(out) <- c("SE_abstraction", "tbl_df", "tbl", "data.frame") - - sub_seq <- if (nn < 2 * top_n) { - seq_len(nn) - } else { - c(seq_len(top_n), (nn - bot_n + 1):nn) - } - out_sub <- out[sub_seq, ] - - if (nrow(out_sub) == nn) { - attr(out_sub, "plyxp:::has_break_at") <- 0L - } else { - attr(out_sub, "plyxp:::has_break_at") <- max(top_n) - } - - attr(out_sub, "plyxp:::data") <- x - print(out_sub, n = n, ...) - invisible(x) - } - - print_plyxp_summarized_experiment(x, ...) - invisible(x) - - # tidyprint_1: SE_print_abstraction - } else if (design == "tidyprint_1"){ - - print_tidyprint_1 <- function(x, n = n_print , ...){ - - onr <- nr <- nrow(x) %>% as.double() - onc <- nc <- ncol(x) %>% as.double() - - if ( onc > 0 && onr > 0 && n / onc >= onr ) { - n <- onc*onr - separator_row_flag = FALSE - }else{ - separator_row_flag = TRUE - } - - top_n <- ceiling(n / 2) - bot_n <- floor(n / 2) - - if (bot_n == 0) separator_row_flag = FALSE - - row_slice <- if (nr < 2 * n) { - seq_len(nr) - } else { - c(seq_len(n), (nr - n + 1):nr) - } - - - col_slice <- if (nc < 2 * n) { - seq_len(nc) - } else { - c(seq_len(n), (nc - n + 1):nc) - } - - x_ <- x[row_slice, col_slice] - nr <- nrow(x_) - nc <- ncol(x_) - .features <- rownames(x_) %||% seq_len(onr)[row_slice] - .samples <- colnames(x_) %||% seq_len(onc)[col_slice] - - assays_ <- purrr::map(assays(x_), as_vec) - row_ <- purrr::map(rowData(x_), vec_rep, times = nc) |> purrr::map(maybe_phantom) - col_ <- purrr::map(colData(x_), vec_rep_each, times = nr) |> purrr::map(maybe_phantom) - - nn <- nc * nr - out <- c( - list( - .feature = vctrs::vec_rep(.features, times = nc), - .sample = vctrs::vec_rep_each(.samples, times = nr) - ), - list(`|` = sep_(nn)), - assays_, - list(`|` = sep_(nn)), - col_, - list(`|` = sep_(nn)), - row_ - ) - attr(out, "row.names") <- c(NA_integer_, -nn) - class(out) <- c("SE_abstraction", "tbl_df", "tbl", "data.frame") - - sub_seq <- if (nn < 2 * top_n) { - seq_len(nn) - } else if (bot_n == 0){ - seq_len(top_n) - } else { - c(seq_len(top_n), (nn - bot_n + 1):nn) - } - - out_sub <- out[sub_seq, ] - - # Compute the max character width for each column - separator_row <- vapply(out_sub %>% colnames(), function(col) { - max_width <- max(nchar(as.character(col)), na.rm = TRUE) # Get max width in the column - paste(rep("-", max_width), collapse = "") # Generate a separator of the same length - }, character(1)) - - if (separator_row_flag){ - - # Modify the entire tibble to include a separator row across all columns - ## temporalily convert factor cols to char - fct_col = map(out_sub, is.factor) %>% keep(~{.x == TRUE}) %>% names - if (length(fct_col)) out_sub[, fct_col] = out_sub[, fct_col] %>% mutate(across(all_of(fct_col), as.character)) - - - out_sub <- suppressWarnings(rbind( - out_sub[seq_len(top_n),], - as.list(separator_row), # Adaptive separator row - out_sub[(top_n+1):nrow(out_sub), ] - )) - ## reverse to factor cols - if (length(fct_col)) out_sub[, fct_col] = out_sub[, fct_col] %>% mutate(across(all_of(fct_col), as.factor)) - } - - # attr(out_sub, "n") <- n - # attr(out_sub, "total_rows") <- x %>% dim %>% {(.)[1] * (.)[2]} - - # class(out_sub) <- c("SE_print_abstraction", "tbl_df", "tbl", "data.frame") - - 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(onc*onr, 'total_rows') %>% - add_attr(nrow(x), "number_of_features") %>% - add_attr(ncol(x), "number_of_samples") %>% - add_attr(assays(x) %>% names, "assay_names") %>% - add_attr(separator_row, "separator_row") |> - add_attr(names(col_), "covariate_names") |> - - # add_attr( - # # Get the actual column names that will be printed on screen - # # This uses tibble's internal method to determine visible columns - # pillar::tbl_format_setup(out_sub, width = getOption("width", 80) + 4)$body[1] |> as.character(), - # "printed_colnames" - # ) %>% - add_attr( - '' %>% - setNames("A SummarizedExperiment-tibble abstraction"), - "named_header" - ) - - # print(attributes(out_sub)) - - out_sub %>% print(n = ifelse(separator_row_flag, n+1, n), ...) - invisible(x) - } - - - print_tidyprint_1(x, ...) - invisible(x) + + col_slice <- if (nc < 2 * n) { + seq_len(nc) + } else { + c(seq_len(n), (nc - n + 1):nc) + } + x_ <- x[row_slice, col_slice] + nr <- nrow(x_) + nc <- ncol(x_) + .features <- rownames(x_) %||% seq_len(onr)[row_slice] + .samples <- colnames(x_) %||% seq_len(onc)[col_slice] + + assays_ <- purrr::map(assays(x_), as_vec) + row_ <- purrr::map(rowData(x_), vec_rep, times = nc) |> purrr::map(maybe_phantom) + col_ <- purrr::map(colData(x_), vec_rep_each, times = nr) |> purrr::map(maybe_phantom) + + nn <- nc * nr + out <- c( + list( + .feature = vctrs::vec_rep(.features, times = nc), + .sample = vctrs::vec_rep_each(.samples, times = nr) + ), + list(`|` = sep_(nn)), + assays_, + list(`|` = sep_(nn)), + col_, + list(`|` = sep_(nn)), + row_ + ) + attr(out, "row.names") <- c(NA_integer_, -nn) + class(out) <- c("SE_abstraction", "tbl_df", "tbl", "data.frame") + + sub_seq <- if (nn < 2 * top_n) { + seq_len(nn) + } else if (bot_n == 0){ + seq_len(top_n) } else { - stop("Invalid design argument.") + c(seq_len(top_n), (nn - bot_n + 1):nn) + } + + out_sub <- out[sub_seq, ] + + # Compute the max character width for each column + separator_row <- vapply(out_sub %>% colnames(), function(col) { + max_width <- max(nchar(as.character(col)), na.rm = TRUE) # Get max width in the column + paste(rep("-", max_width), collapse = "") # Generate a separator of the same length + }, character(1)) + + if (separator_row_flag){ + + # Modify the entire tibble to include a separator row across all columns + ## temporalily convert factor cols to char + fct_col = map(out_sub, is.factor) %>% keep(~{.x == TRUE}) %>% names + if (length(fct_col)) out_sub[, fct_col] = out_sub[, fct_col] %>% mutate(across(all_of(fct_col), as.character)) + + + out_sub <- suppressWarnings(rbind( + out_sub[seq_len(top_n),], + as.list(separator_row), # Adaptive separator row + out_sub[(top_n+1):nrow(out_sub), ] + )) + ## reverse to factor cols + if (length(fct_col)) out_sub[, fct_col] = out_sub[, fct_col] %>% mutate(across(all_of(fct_col), as.factor)) } + + out_sub = out_sub %>% + vctrs::new_data_frame(class=c('SE_print_abstraction', "tbl_df", "tbl", "data.frame")) %>% + add_attr(n, 'n') %>% + add_attr(onc*onr, 'total_rows') %>% + add_attr(nrow(x), "number_of_features") %>% + add_attr(ncol(x), "number_of_samples") %>% + add_attr(assays(x) %>% names, "assay_names") %>% + add_attr(separator_row, "separator_row") |> + add_attr(names(col_), "covariate_names") |> + add_attr( + '' %>% + setNames("A SummarizedExperiment-tibble abstraction"), + "named_header" + ) + + out_sub %>% print(n = ifelse(separator_row_flag, n+1, n), ...) + invisible(x) } # Assign the new print function to SummarizedExperiment objects 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/README.md b/README.md index 997c582..171c64c 100644 --- a/README.md +++ b/README.md @@ -46,17 +46,7 @@ visualization and user experience when working with genomic data. ### Package Overview -To facilitate the discussion about data display, we compare here four -data displays: - -1. **SummarizedExperiment**: Standard R/SummarizedExperiment printing - style. - -2. **tidyprint_1**: Newly designed tibble abstraction, combines styles - from **tidySummarizedExperiment** and **plyxp** with updated design. - -Depending on your workflow and desired console output, `tidyprint` makes -it easy to switch between these printing styles. +**tidyprint** provides an improved display for SummarizedExperiment objects with a tidy tibble-style format that makes genomic data more accessible and easier to explore. ------------------------------------------------------------------------ @@ -145,65 +135,6 @@ airway #> # seq_name , seq_strand , seq_coord_system , symbol ``` ------------------------------------------------------------------------- - -**For comparative purposes we display the alternative visualisations we -are trying to harmonise (now depreciated)** - -### **tidySummarizedExperiment** - -Use the “tidySummarizedExperiment” design to view your data in a -**tidy-friendly tibble** format: - -``` r -# Tidy SummarizedExperiment print: -airway %>% print(design = "tidySummarizedExperiment") -#> # A SummarizedExperiment-tibble abstraction: 509,416 × 23 -#> # Features=63677 | Samples=8 | Assays=counts -#> .feature .sample counts SampleName cell dex albut Run avgLength -#> -#> 1 ENSG00000000003 SRR10395… 679 GSM1275862 N613… untrt untrt SRR1… 126 -#> 2 ENSG00000000005 SRR10395… 0 GSM1275862 N613… untrt untrt SRR1… 126 -#> 3 ENSG00000000419 SRR10395… 467 GSM1275862 N613… untrt untrt SRR1… 126 -#> 4 ENSG00000000457 SRR10395… 260 GSM1275862 N613… untrt untrt SRR1… 126 -#> 5 ENSG00000000460 SRR10395… 60 GSM1275862 N613… untrt untrt SRR1… 126 -#> 6 ENSG00000000938 SRR10395… 0 GSM1275862 N613… untrt untrt SRR1… 126 -#> 7 ENSG00000000971 SRR10395… 3251 GSM1275862 N613… untrt untrt SRR1… 126 -#> 8 ENSG00000001036 SRR10395… 1433 GSM1275862 N613… untrt untrt SRR1… 126 -#> 9 ENSG00000001084 SRR10395… 519 GSM1275862 N613… untrt untrt SRR1… 126 -#> 10 ENSG00000001167 SRR10395… 394 GSM1275862 N613… untrt untrt SRR1… 126 -#> # ℹ 40 more rows -#> # ℹ 14 more variables: Experiment , Sample , BioSample , -#> # gene_id , gene_name , entrezid , gene_biotype , -#> # gene_seq_start , gene_seq_end , seq_name , seq_strand , -#> # seq_coord_system , symbol , GRangesList -``` - -### **plyxp** - -For a more compact view (top and bottom rows), similar to a -plyxp/tidyverse style: - -``` r -airway %>% print(design = "plyxp") -#> # A tibble: 10 × 25 -#> .features .samples `|` counts `|` gene_id gene_name entrezid gene_biotype -#> <|> <|> -#> 1 ENSG0000… SRR1039… | 679 | ENSG000000… TSPAN6 NA protein_cod… -#> 2 ENSG0000… SRR1039… | 0 | ENSG000000… TNMD NA protein_cod… -#> 3 ENSG0000… SRR1039… | 467 | ENSG000000… DPM1 NA protein_cod… -#> 4 ENSG0000… SRR1039… | 260 | ENSG000000… SCYL3 NA protein_cod… -#> 5 ENSG0000… SRR1039… | 60 | ENSG000000… C1orf112 NA protein_cod… -#> 6 ENSG0000… SRR1039… | 0 | ENSG000002… RP11-180… NA antisense -#> 7 ENSG0000… SRR1039… | 0 | ENSG000002… TSEN34 NA protein_cod… -#> 8 ENSG0000… SRR1039… | 0 | ENSG000002… RP11-138… NA lincRNA -#> 9 ENSG0000… SRR1039… | 0 | ENSG000002… AP000230… NA lincRNA -#> 10 ENSG0000… SRR1039… | 0 | ENSG000002… RP11-80H… NA lincRNA -#> # ℹ 16 more variables: gene_seq_start , gene_seq_end , -#> # seq_name , seq_strand , seq_coord_system , symbol , -#> # `|` <|>, SampleName , cell , dex , albut , Run , -#> # avgLength , Experiment , Sample , BioSample -``` ## Messaging function diff --git a/man/print.SummarizedExperiment.Rd b/man/print.SummarizedExperiment.Rd index e7f7587..1bb1979 100644 --- a/man/print.SummarizedExperiment.Rd +++ b/man/print.SummarizedExperiment.Rd @@ -4,28 +4,14 @@ \alias{print.SummarizedExperiment} \title{Print method for SummarizedExperiment with tidyprint styles} \usage{ -\method{print}{SummarizedExperiment}(x, design = 2, n_print = 10, ...) +\method{print}{SummarizedExperiment}(x, n = 10, ...) } \arguments{ \item{x}{A \code{SummarizedExperiment} object to print.} -\item{design}{Either a character string or integer selecting the print style. -Character choices are: -\itemize{ -\item \code{"SummarizedExperiment"} — standard Bioconductor summary. -\item \code{"tidyprint_1"} — tidyprint tibble abstraction (top/bottom slices, -assays | colData | rowData blocks, with an adaptive separator row). -} -Numeric shortcuts are mapped as: -\itemize{ -\item \code{1} \eqn{\to} \code{"SummarizedExperiment"} -\item \code{2} \eqn{\to} \code{"tidyprint_1"} -}} - -\item{n_print}{Integer (default \code{10}). Approximate number of rows to show -in the \code{"tidyprint_1"} display. When the total cells shown are fewer -than \code{n_print}, the full table is printed and the separator row is -suppressed.} +\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).} } @@ -33,16 +19,13 @@ suppressed.} \code{x} is returned \emph{invisibly} after printing. } \description{ -Provides alternative console displays for a \link[SummarizedExperiment]{SummarizedExperiment} -object. The default shows the standard Bioconductor summary. The -\code{"tidyprint_1"} design prints a compact tibble-like abstraction that -preserves assay values and key covariates with a separator band when +Provides a compact tibble-like display for a \link[SummarizedExperiment]{SummarizedExperiment} +object that preserves assay values and key covariates with a separator band when the table is truncated. } \details{ -The \code{"tidyprint_1"} design constructs a tibble abstraction for SummarizedExperiment -data with columns: -\code{.feature}, \code{.sample}, assay columns, a vertical separator \code{"|"}, +This method constructs a tibble abstraction for SummarizedExperiment data with +columns: \code{.feature}, \code{.sample}, assay columns, a vertical separator \code{"|"}, followed by selected \code{colData} and \code{rowData} fields. When the output is truncated, an adaptive dash-only separator row is inserted after the first half block of rows. Additional indication of \code{colData} is provided as well. @@ -50,9 +33,8 @@ half block of rows. Additional indication of \code{colData} is provided as well. \examples{ \dontrun{ library(tidyprint) - print(se_airway) # default - print(se_airway, design = "tidyprint_1") # tidyprint abstraction - print(se_airway, design = 2) # numeric alias for "tidyprint_1" + print(se_airway) # compact tibble display + 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 c937eea..4c51152 100644 --- a/tests/testthat/test-print_methods.R +++ b/tests/testthat/test-print_methods.R @@ -8,52 +8,13 @@ library(tidyprint) data(se_airway) -# test for default design -test_that("Default SummarizedExperiment print works", { +# test for default print +test_that("Default print works", { expect_output(print(se_airway), "A SummarizedExperiment-tibble abstraction:") }) -test_that("Default SummarizedExperiment print works", { - expect_output(print(se_airway, design = 1), "class: SummarizedExperiment") -}) - -test_that("Default SummarizedExperiment print works", { - expect_output(print(se_airway, design = "SummarizedExperiment"), "class: SummarizedExperiment") -}) - - - -# test for design 3 -test_that("tidySummarizedExperiment print works", { - expect_output(print(se_airway, design = "tidySummarizedExperiment"), "A SummarizedExperiment-tibble abstraction:") -}) - -test_that("tidySummarizedExperiment print works", { - expect_output(print(se_airway, design = 3), "A SummarizedExperiment-tibble abstraction:") -}) - - -# test for design 4 -test_that("plyxp print works", { - expect_output(print(se_airway, design = "plyxp"), "A tibble:") -}) - -test_that("plyxp print works", { - expect_output(print(se_airway, design = 4), "A tibble:") -}) - -# test for design 2 -test_that("tidyprint_1 print works", { - expect_output(print(se_airway, design = "tidyprint_1"), "A SummarizedExperiment-tibble abstraction:") -}) - -test_that("tidyprint_1 print works", { - expect_output(print(se_airway, design = 2), "A SummarizedExperiment-tibble abstraction:") -}) - -# test for error -test_that("Invalid design throws an error", { - expect_error(print(se_airway, design = "invalidDesign"), "should be one of") +test_that("Print works with n", { + expect_output(print(se_airway, n = 5), "A SummarizedExperiment-tibble abstraction:") }) # test for message diff --git a/vignettes/Introduction.Rmd b/vignettes/Introduction.Rmd index 269e294..50076dc 100644 --- a/vignettes/Introduction.Rmd +++ b/vignettes/Introduction.Rmd @@ -77,13 +77,7 @@ find_figure <- function(names){ ### Package Overview -To facilitate the discussion about data display, we compare here four data displays: - -1. **SummarizedExperiment**: Standard R/SummarizedExperiment printing style. - -2. **tidyprint_1**: Newly designed tibble abstraction, combines styles from **tidySummarizedExperiment** and **plyxp** with updated design. - -Depending on your workflow and desired console output, `tidyprint` makes it easy to switch between these printing styles. +**tidyprint** provides an improved display for SummarizedExperiment objects with a tidy tibble-style format that makes genomic data more accessible and easier to explore. ------------------------------------------------------------------------ @@ -141,26 +135,6 @@ library(tidyprint) airway ``` ------------------------------------------------------------------------- - -**For comparative purposes we display the alternative visualisations we are trying to harmonise (now depreciated)** - -### **tidySummarizedExperiment** - -Use the "tidySummarizedExperiment" design to view your data in a **tidy-friendly tibble** format: - -```{r tidyse-display} -# Tidy SummarizedExperiment print: -airway %>% print(design = "tidySummarizedExperiment") -``` - -### **plyxp** - -For a more compact view (top and bottom rows), similar to a plyxp/tidyverse style: - -```{r plyxp-display} -airway %>% print(design = "plyxp") -``` ## Messaging function