|
| 1 | +#' Print method for SummarizedExperiment with tidyprint styles |
| 2 | +#' |
| 3 | +#' Provides alternative console displays for a \link[SummarizedExperiment]{SummarizedExperiment} |
| 4 | +#' object. The default shows the standard Bioconductor summary. The |
| 5 | +#' `"tidyprint_1"` design prints a compact tibble-like abstraction that |
| 6 | +#' preserves assay values and key covariates with a separator band when |
| 7 | +#' the table is truncated. |
| 8 | +#' |
| 9 | +#' @param x A \code{SummarizedExperiment} object to print. |
| 10 | +#' @param design Either a character string or integer selecting the print style. |
| 11 | +#' Character choices are: |
| 12 | +#' \itemize{ |
| 13 | +#' \item \code{"SummarizedExperiment"} — standard Bioconductor summary. |
| 14 | +#' \item \code{"tidyprint_1"} — tidyprint tibble abstraction (top/bottom slices, |
| 15 | +#' assays | colData | rowData blocks, with an adaptive separator row). |
| 16 | +#' } |
| 17 | +#' Numeric shortcuts are mapped as: |
| 18 | +#' \itemize{ |
| 19 | +#' \item \code{1} \eqn{\to} \code{"SummarizedExperiment"} |
| 20 | +#' \item \code{2} \eqn{\to} \code{"tidyprint_1"} |
| 21 | +#' } |
| 22 | +#' @param n_print Integer (default \code{10}). Approximate number of rows to show |
| 23 | +#' in the \code{"tidyprint_1"} display. When the total cells shown are fewer |
| 24 | +#' than \code{n_print}, the full table is printed and the separator row is |
| 25 | +#' suppressed. |
| 26 | +#' @param ... Additional arguments passed to internal printers (currently unused). |
| 27 | +#' |
| 28 | +#' @details |
| 29 | +#' The \code{"tidyprint_1"} design constructs a tibble abstraction for SummarizedExperiment |
| 30 | +#' data with columns: |
| 31 | +#' \code{.feature}, \code{.sample}, assay columns, a vertical separator \code{"|"}, |
| 32 | +#' followed by selected \code{colData} and \code{rowData} fields. When the output |
| 33 | +#' is truncated, an adaptive dash-only separator row is inserted after the first |
| 34 | +#' half block of rows. Additional indication of \code{colData} is provided as well. |
| 35 | +#' |
| 36 | +#' @return \code{x} is returned \emph{invisibly} after printing. |
| 37 | +#' |
| 38 | +#' @seealso \link[SummarizedExperiment]{SummarizedExperiment}, \link[tibble]{as_tibble} |
| 39 | +#' |
| 40 | +#' @examples |
| 41 | +#' \dontrun{ |
| 42 | +#' library(tidyprint) |
| 43 | +#' print(se_airway) # default |
| 44 | +#' print(se_airway, design = "tidyprint_1") # tidyprint abstraction |
| 45 | +#' print(se_airway, design = 2) # numeric alias for "tidyprint_1" |
| 46 | +#' } |
| 47 | +#' |
1 | 48 | #' @importClassesFrom SummarizedExperiment SummarizedExperiment |
2 | 49 | #' @importFrom methods setMethod |
3 | 50 |
|
|
11 | 58 | #' @importFrom magrittr `%>%` |
12 | 59 | #' @importFrom dplyr if_else mutate across |
13 | 60 | #' @export |
14 | | -print.SummarizedExperiment <- function(x, design = 4, n_print = 10, ...) { |
| 61 | +print.SummarizedExperiment <- function(x, design = 2, n_print = 10, ...) { |
15 | 62 |
|
16 | 63 | # Match the user-supplied design argument to one of the valid choices: |
17 | 64 | if (is.numeric(design)) { |
18 | 65 | # Allowed numeric -> corresponding design |
19 | | - design_map <- c("SummarizedExperiment", "tidySummarizedExperiment", "plyxp", "tidyprint_1") |
20 | | - |
| 66 | + # design_map <- c("SummarizedExperiment", "tidySummarizedExperiment", "plyxp", "tidyprint_1") |
| 67 | + design_map <- c("SummarizedExperiment", "tidyprint_1") |
| 68 | + |
21 | 69 | # Validate numeric input |
22 | | - if (!design %in% 1:4) { |
23 | | - stop("Invalid numeric design argument. Choose 1, 2, 3, or 4.") |
| 70 | + if (!design %in% 1:2) { |
| 71 | + stop("Invalid numeric design argument. Choose 1 or 2.") |
24 | 72 | } |
25 | 73 | design <- design_map[design] |
26 | 74 | } |
27 | 75 |
|
28 | | - design <- match.arg(design, c("SummarizedExperiment", "tidyprint_1", "tidySummarizedExperiment", "plyxp")) |
| 76 | + # design <- match.arg(design, c("SummarizedExperiment", "tidyprint_1", "tidySummarizedExperiment", "plyxp")) |
| 77 | + design <- match.arg(design, c("SummarizedExperiment", "tidyprint_1")) |
| 78 | + |
29 | 79 |
|
30 | 80 | if (!inherits(x, "SummarizedExperiment")) { |
31 | 81 | stop("The object provided is not a SummarizedExperiment.") |
|
0 commit comments