diff --git a/NAMESPACE b/NAMESPACE index 45635a7..45180bc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -62,7 +62,10 @@ importFrom(SummarizedExperiment,assay) importFrom(SummarizedExperiment,assayNames) importFrom(SummarizedExperiment,assays) importFrom(SummarizedExperiment,colData) +importFrom(crayon,red) +importFrom(dplyr,across) importFrom(dplyr,add_count) +importFrom(dplyr,all_of) importFrom(dplyr,any_of) importFrom(dplyr,arrange) importFrom(dplyr,contains) diff --git a/R/print_method.R b/R/print_method.R index bdef4ae..666bb0d 100755 --- a/R/print_method.R +++ b/R/print_method.R @@ -46,20 +46,39 @@ tbl_format_header.tidySingleCellExperiment <- function(x, setup, ...) { #' @return Prints a message to the console describing #' the contents of the `tidySingleCellExperiment`. #' +#' @param x A SingleCellExperiment object. +#' @param n (optional) The maximum number of rows to show. +#' @param width (optional) The maximum width of the output. #' @examples #' data(pbmc_small) #' print(pbmc_small) -#' +#' #' @importFrom vctrs new_data_frame #' @importFrom SummarizedExperiment assayNames +#' @importFrom crayon red +#' @importFrom dplyr mutate across all_of +#' @importFrom crayon red #' @export print.SingleCellExperiment <- function(x, ..., n=NULL, width=NULL) { - x |> - as_tibble(n_dimensions_to_return=5) |> - new_data_frame(class=c("tidySingleCellExperiment", "tbl")) %>% + # Retrieve special view-only columns + special_cols <- get_special_columns(x) + + # Convert to tibble + tibble_x <- x |> as_tibble(n_dimensions_to_return=5) + + # Modify column titles for special columns + col_titles <- names(tibble_x) + modified_col_titles <- ifelse(col_titles %in% special_cols, + crayon::red(as.character(col_titles)), + col_titles) + + names(tibble_x) <- modified_col_titles + + # Print the tibble with modified column titles + new_data_frame(tibble_x, class=c("tidySingleCellExperiment", "tbl")) %>% add_attr(nrow(x), "number_of_features") %>% add_attr(assayNames(x), "assay_names") %>% - print() - + print(n = n, width = width) + invisible(x) -} +} \ No newline at end of file