Skip to content

Commit d7c1b50

Browse files
committed
resovle R CMD test warnings
1 parent 504eacf commit d7c1b50

File tree

4 files changed

+47
-53
lines changed

4 files changed

+47
-53
lines changed

R/print_methods.R

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#' @importFrom SummarizedExperiment assayNames assays rowData assays<- rowRanges
5454
#' @importFrom stats setNames
5555
#' @importFrom S4Vectors coolcat
56-
#' @importFrom purrr when map_chr keep
56+
#' @importFrom purrr map_chr keep
5757
#' @importFrom stringr str_replace
5858
#' @importFrom magrittr `%>%`
5959
#' @importFrom dplyr if_else mutate across
@@ -137,14 +137,15 @@ but they do not completely overlap.")
137137
# Reorder assays before printing
138138
x <- order_assays_internally_to_be_consistent(x)
139139

140-
my_tibble <- x |>
141-
# If more than 30 genes, select first sample
142-
when(
143-
nrow(.) > 30 ~.[1:min(50, nrow(x)), min(1, ncol(x)), drop=FALSE] ,
144-
ncol(.) == 0 ~ .,
145-
~ .[, 1:min(20, ncol(x)), drop=FALSE]
146-
) %>%
147-
as_tibble()
140+
tmp_x <- x
141+
if (nrow(tmp_x) > 30) {
142+
tmp_x <- tmp_x[1:min(50, nrow(x)), min(1, ncol(x)), drop = FALSE]
143+
} else if (ncol(tmp_x) == 0) {
144+
tmp_x <- tmp_x
145+
} else {
146+
tmp_x <- tmp_x[, 1:min(20, ncol(x)), drop = FALSE]
147+
}
148+
my_tibble <- tmp_x %>% as_tibble()
148149

149150
my_tibble |>
150151
vctrs::new_data_frame(class=c("tidySummarizedExperiment", "tbl")) %>%

R/tibble_methods.R

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ as_tibble.SummarizedExperiment <- function(x, ...,
3333
setNames(c(s_(x)$name, colnames(colData(x))))
3434

3535
range_info <-
36-
skip_GRanges %>%
37-
when(
38-
(.) ~ tibble() %>% list,
39-
~ get_special_datasets(x)
40-
) %>%
41-
reduce(left_join, by="coordinate")
36+
{
37+
if (isTRUE(skip_GRanges)) {
38+
list(tibble())
39+
} else {
40+
get_special_datasets(x)
41+
}
42+
} %>%
43+
reduce(left_join, by = "coordinate")
4244

4345
gene_info <-
4446
rowData(x) %>%
@@ -59,9 +61,13 @@ as_tibble.SummarizedExperiment <- function(x, ...,
5961
count_info %>%
6062
full_join(sample_info, by=s_(x)$name) %>%
6163
full_join(gene_info, by=f_(x)$name) %>%
62-
when(nrow(range_info) > 0 ~
63-
(.) %>% left_join(range_info) %>% suppressMessages(),
64-
~ (.))
64+
{
65+
if (nrow(range_info) > 0) {
66+
suppressMessages(left_join(., range_info))
67+
} else {
68+
.
69+
}
70+
}
6571

6672
# This function outputs a tibble after subsetting the columns
6773
else subset_tibble_output(x, count_info, sample_info,

R/tidyse_utils.R

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -274,42 +274,26 @@ get_special_datasets <- function(se) {
274274
rowRanges()
275275

276276
rr %>%
277-
when(
278-
279-
# If no ranges
280-
as.data.frame(.) %>%
281-
nrow() %>%
282-
magrittr::equals(0) ~ tibble(),
283-
284-
# If it is a range list (multiple rows per feature)
285-
is(., "CompressedGRangesList") ~ {
286-
287-
# If GRanges does not have row names
277+
{
278+
if (nrow(as.data.frame(.)) == 0) {
279+
tibble()
280+
} else if (is(., "CompressedGRangesList")) {
288281
if (is.null(rr@partitioning@NAMES)) {
289282
rr@partitioning@NAMES <- as.character(1:nrow(se))
290283
}
291-
292284
tibble::as_tibble(rr) %>%
293285
eliminate_GRanges_metadata_columns_also_present_in_Rowdata(se) %>%
294286
nest(GRangesList = -group_name) %>%
295287
dplyr::rename(!!f_(se)$symbol := group_name)
296-
297-
},
298-
299-
# If standard GRanges (one feature per line)
300-
~ {
301-
302-
# If GRanges does not have row names
288+
} else {
303289
if (is.null(rr@ranges@NAMES)) {
304290
rr@ranges@NAMES <- as.character(1:nrow(se))
305291
}
306-
307292
tibble::as_tibble(rr) %>%
308293
eliminate_GRanges_metadata_columns_also_present_in_Rowdata(se) %>%
309294
mutate(!!f_(se)$symbol := rr@ranges@NAMES)
310295
}
311-
312-
) %>%
296+
} %>%
313297
list()
314298
}
315299

@@ -388,13 +372,13 @@ get_count_datasets <- function(se) {
388372
# In case I have a sparse matrix
389373
as.matrix() |>
390374
tibble::as_tibble(rownames = f_(se)$name, .name_repair = "minimal") %>%
391-
392-
# If the matrix does not have sample names, fix column names
393-
when(colnames(.x) %>% is.null() & is.null(colnames(se)) ~ setNames(., c(
394-
f_(se)$name, seq_len(ncol(.x))
395-
)),
396-
~ (.)
397-
)
375+
{
376+
if (is.null(colnames(.x)) && is.null(colnames(se))) {
377+
setNames(., c(f_(se)$name, seq_len(ncol(.x))))
378+
} else {
379+
.
380+
}
381+
}
398382

399383
# Avoid dug if SE if completely empty, no rows, no columns
400384
if(.x |> select(-!!f_(se)$symbol) |> ncol() == 0) return(.x)
@@ -408,11 +392,15 @@ get_count_datasets <- function(se) {
408392

409393
# Add dummy sample or feature if we have empty assay.
410394
# This is needed for a correct visualisation of the tibble form
411-
map(~when(
412-
f_(se)$name %in% colnames(.x) %>% not ~ mutate(.x, !!f_(se)$symbol := as.character(NA)),
413-
s_(se)$name %in% colnames(.x) %>% not ~ mutate(.x, !!s_(se)$symbol := as.character(NA)),
414-
~ .x
415-
))
395+
map(~{
396+
if (!(f_(se)$name %in% colnames(.x))) {
397+
mutate(.x, !!f_(se)$symbol := as.character(NA))
398+
} else if (!(s_(se)$name %in% colnames(.x))) {
399+
mutate(.x, !!s_(se)$symbol := as.character(NA))
400+
} else {
401+
.x
402+
}
403+
})
416404

417405
# If assays is non empty
418406
if(list_assays |> length() > 0)

tests/testthat/test-header-formatting.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ library(stringr)
44
library(dplyr)
55
library(tidyprint)
66

7-
context("format_covariate_header")
87

98
separator_row <- c(
109
".feature" = " ",

0 commit comments

Comments
 (0)