From 5ac207ed704858163625995b0c7f142cc7c12deb Mon Sep 17 00:00:00 2001 From: Biomiha Date: Wed, 23 Aug 2023 20:48:17 +0100 Subject: [PATCH 1/4] test change print_method.R --- R/print_method.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/print_method.R b/R/print_method.R index 14d0ec6..2bc8980 100755 --- a/R/print_method.R +++ b/R/print_method.R @@ -36,7 +36,7 @@ tbl_format_header.tidySingleCellExperiment <- function(x, setup, ...){ # Add further info single-cell append(sprintf( - "\033[90m Features=%s | Cells=%s | Assays=%s\033[39m", + "\033[90m Creatures=%s | Cells=%s | Assays=%s\033[39m", number_of_features, nrow(x), assay_names %>% paste(collapse=", ") From c1db700e2102a88c11276cd2c2b54cdd6afc3e42 Mon Sep 17 00:00:00 2001 From: Biomiha Date: Wed, 23 Aug 2023 21:52:05 +0100 Subject: [PATCH 2/4] Update print_method.R --- R/print_method.R | 89 +++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/R/print_method.R b/R/print_method.R index 2bc8980..813c699 100755 --- a/R/print_method.R +++ b/R/print_method.R @@ -1,4 +1,5 @@ -# This file is a replacement of the unexported functions in the tibble package, in order to specify "tibble abstraction in the header" +# This file is a replacement of the unexported functions in the tibble +# package, in order to specify "tibble abstraction in the header" #' @name tbl_format_header #' @rdname tbl_format_header @@ -13,62 +14,56 @@ #' @importFrom pillar style_subtle #' @importFrom pillar tbl_format_header #' @export -tbl_format_header.tidySingleCellExperiment <- function(x, setup, ...){ - - number_of_features = x |> attr("number_of_features") - assay_names = x |> attr("assay_names") - - named_header <- setup$tbl_sum - - # Change name - names(named_header) = "A SingleCellExperiment-tibble abstraction" - - if (all(names2(named_header) == "")) { - header <- named_header - } - else { - header <- - paste0( - align(paste0(names2(named_header), ":"), space = NBSP), - " ", - named_header - ) %>% - - # Add further info single-cell - append(sprintf( - "\033[90m Creatures=%s | Cells=%s | Assays=%s\033[39m", - number_of_features, - nrow(x), - assay_names %>% paste(collapse=", ") - ), after = 1) - } - - style_subtle(pillar___format_comment(header, width = setup$width)) - +tbl_format_header.tidySingleCellExperiment <- function(x, setup, ...) { + + number_of_features <- x |> attr("number_of_features") + assay_names <- x |> attr("assay_names") + altExpNames <- x |> attr("altExpNames") + + # Change name + named_header <- setup$tbl_sum + names(named_header) <- "A SingleCellExperiment-tibble abstraction" + + if (all(names2(named_header) == "")) { + header <- named_header + } else { + header <- paste0( + align(paste0(names2(named_header), ":"), space=NBSP), + " ", named_header) %>% + # Add further info single-cell + append(sprintf( + "\033[90m Features=%s | Cells=%s | Assays=%s | altExpNames=%s\033[39m", + number_of_features, nrow(x), + paste(assay_names, collapse=", "), + paste(altExpNames, collapse=", ") + ), after=1) + } + style_subtle(pillar___format_comment(header, width=setup$width)) } #' @name formatting #' @rdname formatting #' @aliases print #' @inherit tibble::formatting +#' @return Prints a message to the console describing +#' the contents of the `tidySingleCellExperiment`. #' #' @examples +#' data(pbmc_small) #' print(pbmc_small) #' #' @importFrom vctrs new_data_frame +#' @importFrom SummarizedExperiment assayNames +#' @importFrom SingleCellExperiment altExpNames #' @export -print.SingleCellExperiment <- function(x, ..., n = NULL, width = NULL) {#, n_extra = NULL) { - # TODO: argument 'n_extra' seems to not - # exist anymore; see ?tibble::print.tbl - - x |> - as_tibble(n_dimensions_to_return = 5 ) |> - - new_data_frame(class = c("tidySingleCellExperiment", "tbl")) %>% - add_attr( nrow(x), "number_of_features") %>% - add_attr( assays(x) %>% names , "assay_names") %>% - - print() - - invisible(x) +print.SingleCellExperiment <- function(x, ..., n=NULL, width=NULL) { + x |> + as_tibble(n_dimensions_to_return=5) |> + new_data_frame(class=c("tidySingleCellExperiment", "tbl")) %>% + add_attr(nrow(x), "number_of_features") %>% + add_attr(assayNames(x), "assay_names") %>% + add_attr(altExpNames(x), "altExpNames") %>% + print() + + invisible(x) } From 5a5b71b43e8c56c35a9c084e7df734adca78c682 Mon Sep 17 00:00:00 2001 From: Biomiha Date: Wed, 23 Aug 2023 22:04:15 +0100 Subject: [PATCH 3/4] Update print_method.R --- R/print_method.R | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/R/print_method.R b/R/print_method.R index 813c699..dc16e69 100755 --- a/R/print_method.R +++ b/R/print_method.R @@ -31,12 +31,20 @@ tbl_format_header.tidySingleCellExperiment <- function(x, setup, ...) { align(paste0(names2(named_header), ":"), space=NBSP), " ", named_header) %>% # Add further info single-cell + if(length(altExpNames) != 0) { append(sprintf( - "\033[90m Features=%s | Cells=%s | Assays=%s | altExpNames=%s\033[39m", - number_of_features, nrow(x), - paste(assay_names, collapse=", "), - paste(altExpNames, collapse=", ") + "\033[90m Features=%s | Cells=%s | Assays=%s | altExpNames=%s\033[39m", + number_of_features, nrow(x), + paste(assay_names, collapse=", "), + paste(altExpNames, collapse=", ") ), after=1) + } else { + append(sprintf( + "\033[90m Features=%s | Cells=%s | Assays=%s\033[39m", + number_of_features, nrow(x), + paste(assay_names, collapse=", ") + ), after=1) + } } style_subtle(pillar___format_comment(header, width=setup$width)) } From 67a48f04c31c76f7b7f28a7d6b2def9ca5cfe692 Mon Sep 17 00:00:00 2001 From: Biomiha Date: Wed, 23 Aug 2023 22:17:02 +0100 Subject: [PATCH 4/4] Update print_method.R --- R/print_method.R | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/R/print_method.R b/R/print_method.R index dc16e69..13127e5 100755 --- a/R/print_method.R +++ b/R/print_method.R @@ -31,20 +31,12 @@ tbl_format_header.tidySingleCellExperiment <- function(x, setup, ...) { align(paste0(names2(named_header), ":"), space=NBSP), " ", named_header) %>% # Add further info single-cell - if(length(altExpNames) != 0) { - append(sprintf( + append(sprintf( "\033[90m Features=%s | Cells=%s | Assays=%s | altExpNames=%s\033[39m", number_of_features, nrow(x), paste(assay_names, collapse=", "), - paste(altExpNames, collapse=", ") - ), after=1) - } else { - append(sprintf( - "\033[90m Features=%s | Cells=%s | Assays=%s\033[39m", - number_of_features, nrow(x), - paste(assay_names, collapse=", ") - ), after=1) - } + if(length(nchar(altExpNames)) > 0) paste(altExpNames, collapse=", ") else {"NULL"} + ), after=1) } style_subtle(pillar___format_comment(header, width=setup$width)) }