Skip to content

Commit b698bad

Browse files
committed
Enhance NAMESPACE and README with new imports and examples; update print method for SummarizedExperiment to improve design handling and output formatting.
1 parent a9d0a40 commit b698bad

File tree

9 files changed

+188
-134
lines changed

9 files changed

+188
-134
lines changed

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ importFrom(SummarizedExperiment,colData)
1919
importFrom(SummarizedExperiment,rowData)
2020
importFrom(SummarizedExperiment,rowRanges)
2121
importFrom(cli,col_br_black)
22+
importFrom(dplyr,full_join)
2223
importFrom(dplyr,if_else)
24+
importFrom(dplyr,left_join)
25+
importFrom(dplyr,select)
2326
importFrom(fansi,strwrap_ctl)
2427
importFrom(magrittr,`%>%`)
2528
importFrom(methods,setMethod)
@@ -41,12 +44,15 @@ importFrom(purrr,map_chr)
4144
importFrom(purrr,map_int)
4245
importFrom(purrr,reduce)
4346
importFrom(purrr,when)
47+
importFrom(rlang,enquo)
4448
importFrom(rlang,names2)
4549
importFrom(stats,setNames)
4650
importFrom(stringr,str_replace)
4751
importFrom(stringr,str_replace_all)
4852
importFrom(tibble,as_tibble)
4953
importFrom(tibble,enframe)
54+
importFrom(tidyr,nest)
55+
importFrom(tidyr,pivot_longer)
5056
importFrom(tidyr,spread)
5157
importFrom(vctrs,new_data_frame)
5258
importFrom(vctrs,vec_rep)

R/print_methods.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' @importFrom magrittr `%>%`
1212
#' @importFrom dplyr if_else
1313
#' @export
14-
print.SummarizedExperiment <- function(x, design = 1, n_print = 10, ...) {
14+
print.SummarizedExperiment <- function(x, design = 4, n_print = 10, ...) {
1515

1616
# Match the user-supplied design argument to one of the valid choices:
1717
if (is.numeric(design)) {
@@ -242,8 +242,8 @@ but they do not completely overlap.")
242242
out_sub <- out[sub_seq, ]
243243

244244
# Compute the max character width for each column
245-
separator_row <- map2_chr(out_sub, names(out_sub), ~ {
246-
max_width <- max(nchar(as.character(.x)), na.rm = TRUE) |> max(nchar(.y)) # Get max width in the column
245+
separator_row <- sapply(out_sub %>% colnames(), function(col) {
246+
max_width <- max(nchar(as.character(col)), na.rm = TRUE) # Get max width in the column
247247
paste(rep("-", max_width), collapse = "") # Generate a separator of the same length
248248
})
249249
# Modify the entire tibble to include a separator row across all columns

R/tibble_methods.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
21
#' @importFrom purrr reduce
32
#' @importFrom purrr map map2
43
#' @importFrom tidyr spread
54
#' @importFrom tibble enframe
65
#' @importFrom SummarizedExperiment colData
76
#' @importFrom pkgconfig get_config
7+
#' @importFrom rlang enquo
8+
#' @importFrom dplyr left_join
89
#' @export
910
as_tibble.SummarizedExperiment <- function(x, ...,
1011
.name_repair=c("check_unique", "unique", "universal", "minimal"),
@@ -19,7 +20,7 @@ as_tibble.SummarizedExperiment <- function(x, ...,
1920
.name_repair=c("check_unique", "unique", "universal", "minimal"),
2021
rownames=pkgconfig::get_config("tibble::rownames", NULL)) {
2122

22-
.subset <- enquo(.subset)
23+
.subset <- rlang::enquo(.subset)
2324

2425
sample_info <-
2526
colData(x) %>%

R/tidyprint_1_utlis.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ format_covariate_header <- function(separator_row, printed_colnames, covariate_n
109109

110110
covariate_indices <- which(printed_colnames %in% covariate_names)
111111
covariate_widths <- separator_row[printed_colnames[covariate_indices]] |> purrr::map_int(nchar)
112-
total_covariate_width <- sum(covariate_widths) + length(covariate_widths) + 3 # To compensate the white spaces of the tibble
112+
total_covariate_width <- sum(covariate_widths) + length(covariate_widths) + 1 # To compensate the white spaces of the tibble
113113
label_length <- nchar(label)
114114

115115
# Center the label in the total covariate width, using only dashes and the label
@@ -135,7 +135,7 @@ format_covariate_header <- function(separator_row, printed_colnames, covariate_n
135135
header_row[covariate_indices[-1]] <- ""
136136

137137
# Add row ID spacing at the beginning
138-
header_row <- c(paste(rep(" ", number_of_total_rows |> nchar() - 3), collapse = ""), header_row)
138+
header_row <- c(paste(rep(" ", number_of_total_rows |> nchar() - 4), collapse = ""), header_row)
139139

140140
# Step 2: Collapse everything with space
141141
paste(header_row, collapse = " ")

R/tidyse_utils.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#' @importFrom tidyr nest
2+
#' @importFrom dplyr select
3+
#' @importFrom tidyr pivot_longer
4+
#' @importFrom dplyr full_join
15
# This file is a replacement of the unexported functions in the tibble
26
# package, in order to specify "tibble abstraction in the header"
37

@@ -257,6 +261,14 @@ add_attr <- function(var, attribute, name) {
257261
var
258262
}
259263

264+
eliminate_GRanges_metadata_columns_also_present_in_Rowdata <- function(.my_data, se) {
265+
.my_data %>%
266+
select(-one_of(colnames(rowData(se)))) %>%
267+
268+
# In case there is not metadata column
269+
suppressWarnings()
270+
}
271+
260272
get_special_datasets <- function(se) {
261273

262274
rr = se %>%
@@ -281,7 +293,7 @@ get_special_datasets <- function(se) {
281293
tibble::as_tibble(rr) %>%
282294
eliminate_GRanges_metadata_columns_also_present_in_Rowdata(se) %>%
283295
nest(GRangesList = -group_name) %>%
284-
rename(!!f_(se)$symbol := group_name)
296+
dplyr::rename(!!f_(se)$symbol := group_name)
285297

286298
},
287299

0 commit comments

Comments
 (0)