Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 26 additions & 7 deletions R/print_method.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}