Skip to content

Commit 0b6e2b0

Browse files
committed
Clean up messages in tests
1 parent a2849fc commit 0b6e2b0

20 files changed

+282
-221
lines changed

tests/testthat/test-TreeHeatmap.R

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
test_that("TreeHeatmap works", {
22
## Get some data
33
## -------------------------------------------------------------------------
4-
library(TreeSummarizedExperiment)
5-
library(ggtree)
6-
library(ggplot2)
7-
library(scales)
4+
suppressPackageStartupMessages({
5+
library(TreeSummarizedExperiment)
6+
library(ggtree)
7+
library(ggplot2)
8+
library(scales)
9+
library(GenomeInfoDb)
10+
})
811

912
## Load example data (tiny tree with corresponding count matrix)
1013
tse <- readRDS(system.file("extdata", "tinytree_counts.rds",
1114
package = "treeclimbR"))
1215

1316
## Prepare the tree figure
14-
tree_fig <- ggtree(rowTree(tse), branch.length = "none",
15-
layout = "rectangular", open.angle = 100) +
16-
geom_hilight(node = 18, fill = "orange", alpha = 0.3) +
17-
geom_hilight(node = 13, fill = "blue", alpha = 0.3)
17+
suppressWarnings({
18+
tree_fig <- ggtree(rowTree(tse), branch.length = "none",
19+
layout = "rectangular", open.angle = 100) +
20+
geom_hilight(node = 18, fill = "orange", alpha = 0.3) +
21+
geom_hilight(node = 13, fill = "blue", alpha = 0.3)
22+
})
1823

1924
## Aggregate counts for each of the highlighted subtrees
2025
tseagg <- aggTSE(
@@ -202,19 +207,21 @@ test_that("TreeHeatmap works", {
202207
expect_s3_class(hm, "ggtree")
203208

204209
## Change colors
205-
hm <- TreeHeatmap(tree = rowTree(tseagg), tree_fig = tree_fig,
206-
hm_data = SummarizedExperiment::assay(tseagg, "counts"),
207-
cluster_column = TRUE, column_split = col_split,
208-
column_anno = col_anno, column_anno_gap = 1,
209-
column_anno_color = c(A = "red", B = "blue"),
210-
show_colnames = TRUE, colnames_position = "bottom",
211-
colnames_angle = 90, colnames_size = 2,
212-
colnames_offset_y = -0.4,
213-
show_title = TRUE, title_offset_y = 2,
214-
title_color = "blue") +
215-
scale_fill_gradientn(
216-
colours = c("blue", "yellow", "red"),
217-
values = scales::rescale(c(5, 8, 10)),
218-
guide = "colorbar", limits = c(5, 10))
210+
expect_message({
211+
hm <- TreeHeatmap(tree = rowTree(tseagg), tree_fig = tree_fig,
212+
hm_data = SummarizedExperiment::assay(tseagg, "counts"),
213+
cluster_column = TRUE, column_split = col_split,
214+
column_anno = col_anno, column_anno_gap = 1,
215+
column_anno_color = c(A = "red", B = "blue"),
216+
show_colnames = TRUE, colnames_position = "bottom",
217+
colnames_angle = 90, colnames_size = 2,
218+
colnames_offset_y = -0.4,
219+
show_title = TRUE, title_offset_y = 2,
220+
title_color = "blue") +
221+
scale_fill_gradientn(
222+
colours = c("blue", "yellow", "red"),
223+
values = scales::rescale(c(5, 8, 10)),
224+
guide = "colorbar", limits = c(5, 10))
225+
}, "already present")
219226
expect_s3_class(hm, "ggtree")
220227
})

tests/testthat/test-aggDS.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that("aggDS works", {
22
## Generate example data
3-
library(ape)
3+
suppressPackageStartupMessages(library(ape))
44
tr <- rtree(3, tip.label = LETTERS[seq_len(3)])
55
set.seed(1L)
66
cc <- matrix(rpois(60, 10), nrow = 6)
@@ -204,12 +204,14 @@ test_that("aggDS works", {
204204

205205
## Test that aggregation works - mean
206206
## -------------------------------------------------------------------------
207-
expect_warning({
208-
out <- aggDS(TSE = tse, assay = "counts", sample_id = "sid",
209-
group_id = "gid", cluster_id = "cid", FUN = mean,
210-
message = TRUE)},
211-
"Multiple nodes are found to have the same label"
212-
)
207+
suppressMessages({
208+
expect_warning({
209+
out <- aggDS(TSE = tse, assay = "counts", sample_id = "sid",
210+
group_id = "gid", cluster_id = "cid", FUN = mean,
211+
message = TRUE)},
212+
"Multiple nodes are found to have the same label"
213+
)
214+
})
213215
expect_s4_class(out, "SummarizedExperiment")
214216
expect_equal(nrow(out), nrow(tse))
215217
expect_equal(ncol(out), length(unique(tse$sid)))

tests/testthat/test-diffcyt_workflow.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
test_that("diffcyt workflow works", {
22
## Generate some data and run through diffcyt workflow
33
## -------------------------------------------------------------------------
4-
library(diffcyt)
4+
suppressPackageStartupMessages(library(diffcyt))
55
## Helper function to create random data (one sample)
66
d_random <- function(n = 20000, mean = 0, sd = 1, ncol = 20, cofactor = 5) {
77
d <- sinh(matrix(rnorm(n, mean, sd), ncol = ncol)) * cofactor
@@ -26,7 +26,7 @@ test_that("diffcyt workflow works", {
2626
)
2727
d_se <- diffcyt::prepareData(d_input, experiment_info, marker_info)
2828
d_se <- diffcyt::transformData(d_se)
29-
d_se <- diffcyt::generateClusters(d_se)
29+
suppressMessages({d_se <- diffcyt::generateClusters(d_se)})
3030

3131
## buildTree - check that function errors if provided wrong input
3232
## -------------------------------------------------------------------------
@@ -128,13 +128,15 @@ test_that("diffcyt workflow works", {
128128
}
129129

130130
## Run with message = TRUE
131-
expect_warning({
131+
suppressMessages({
132132
expect_warning({
133133
expect_warning({
134-
out2 <- calcTreeMedians(d_se = d_se, tree = tr, message = TRUE)
134+
expect_warning({
135+
out2 <- calcTreeMedians(d_se = d_se, tree = tr, message = TRUE)
136+
}, "Multiple nodes are found to have the same label")
135137
}, "Multiple nodes are found to have the same label")
136138
}, "Multiple nodes are found to have the same label")
137-
}, "Multiple nodes are found to have the same label")
139+
})
138140
expect_identical(out, out2)
139141

140142
## With missing data (subset cells; some clusters will not have cells from

tests/testthat/test-evalCand.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that(".pseudoLeaf works", {
2-
library(TreeSummarizedExperiment)
3-
library(ggtree)
2+
suppressPackageStartupMessages(library(TreeSummarizedExperiment))
3+
suppressPackageStartupMessages(library(ggtree))
44
data(tinyTree)
55
set.seed(1)
66
pv <- runif(19, 0, 1)
@@ -41,7 +41,7 @@ test_that(".pseudoLeaf works", {
4141

4242
test_that("evalCand works", {
4343
## Generate some data
44-
library(TreeSummarizedExperiment)
44+
suppressPackageStartupMessages(library(TreeSummarizedExperiment))
4545
data(tinyTree)
4646
set.seed(1)
4747
pv <- runif(19, 0, 1)
@@ -445,16 +445,18 @@ test_that("evalCand works", {
445445
ignore_attr = TRUE)
446446

447447
## Multiple - use pseudo leaf
448-
out <- evalCand(tree = tinyTree, type = "multiple",
449-
levels = list(gene1 = ll$candidate_list,
450-
gene2 = llna$candidate_list),
451-
score_data = list(gene1 = ll$score_data,
452-
gene2 = llna$score_data),
453-
node_column = "node", p_column = "pvalue",
454-
sign_column = "foldChange",
455-
feature_column = "feature", method = "BH",
456-
limit_rej = 0.05, use_pseudo_leaf = TRUE,
457-
message = TRUE)
448+
suppressMessages({
449+
out <- evalCand(tree = tinyTree, type = "multiple",
450+
levels = list(gene1 = ll$candidate_list,
451+
gene2 = llna$candidate_list),
452+
score_data = list(gene1 = ll$score_data,
453+
gene2 = llna$score_data),
454+
node_column = "node", p_column = "pvalue",
455+
sign_column = "foldChange",
456+
feature_column = "feature", method = "BH",
457+
limit_rej = 0.05, use_pseudo_leaf = TRUE,
458+
message = TRUE)
459+
})
458460
expect_type(out, "list")
459461
expect_named(out, c("candidate_best", "output", "candidate_list",
460462
"level_info", "FDR", "method", "column_info"))

tests/testthat/test-getCand.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that("getCand works", {
22
## Generate some data
3-
library(TreeSummarizedExperiment)
3+
suppressPackageStartupMessages(library(TreeSummarizedExperiment))
44
data(tinyTree)
55
set.seed(1)
66
pv <- runif(19, 0, 1)
@@ -265,11 +265,13 @@ test_that("getCand works", {
265265
## children have valid p-values.
266266
df2 <- df
267267
df2$pvalue[df2$node %in% c(1, 2, 4, 13)] <- NA
268-
ll <- getCand(tree = tinyTree, score_data = df2,
269-
t = c(0.01, 0.05, 0.1, 0.25, 0.75),
270-
node_column = "node", p_column = "pvalue",
271-
sign_column = "foldChange", threshold = 0.05,
272-
pct_na = 0.75, message = TRUE)
268+
suppressMessages({
269+
ll <- getCand(tree = tinyTree, score_data = df2,
270+
t = c(0.01, 0.05, 0.1, 0.25, 0.75),
271+
node_column = "node", p_column = "pvalue",
272+
sign_column = "foldChange", threshold = 0.05,
273+
pct_na = 0.75, message = TRUE)
274+
})
273275
expect_type(ll, "list")
274276
expect_named(ll, c("candidate_list", "score_data"))
275277
expect_type(ll$candidate_list, "list")

tests/testthat/test-getData.R

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
test_that("getData works", {
22
## Generate some data
33
## -------------------------------------------------------------------------
4-
library(TreeSummarizedExperiment)
5-
library(ggtree)
6-
library(ggplot2)
7-
library(ggnewscale)
8-
library(viridis)
9-
library(dplyr)
4+
suppressPackageStartupMessages({
5+
library(TreeSummarizedExperiment)
6+
library(ggtree)
7+
library(ggplot2)
8+
library(ggnewscale)
9+
library(viridis)
10+
library(dplyr)
11+
})
1012

1113
data(tinyTree)
1214

@@ -28,10 +30,12 @@ test_that("getData works", {
2830
names(col_split) <- colnames(ct)
2931

3032
## Prepare the heatmaps
31-
tree_fig <- ggtree(tinyTree, branch.length = "none",
32-
layout = "rectangular", open.angle = 100) +
33-
geom_hilight(node = 18, fill = "orange", alpha = 0.3) +
34-
geom_hilight(node = 13, fill = "blue", alpha = 0.3)
33+
suppressWarnings({
34+
tree_fig <- ggtree(tinyTree, branch.length = "none",
35+
layout = "rectangular", open.angle = 100) +
36+
geom_hilight(node = 18, fill = "orange", alpha = 0.3) +
37+
geom_hilight(node = 13, fill = "blue", alpha = 0.3)
38+
})
3539
fig <- TreeHeatmap(
3640
tree = tinyTree, tree_fig = tree_fig, hm_data = ct,
3741
cluster_column = TRUE, column_split = col_split,
@@ -55,8 +59,10 @@ test_that("getData works", {
5559
)
5660

5761
## Figure with scaled tree
58-
tree_fig_sc <- ggtree(tinyTree, branch.length = "none",
59-
layout = "rectangular", open.angle = 100)
62+
expect_warning({
63+
tree_fig_sc <- ggtree(tinyTree, branch.length = "none",
64+
layout = "rectangular", open.angle = 100)
65+
}, "must be used")
6066
tree_fig_sc <- ggtree::scaleClade(tree_fig_sc, node = 15, scale = 4)
6167
tree_fig_sc <- ggtree::scaleClade(tree_fig_sc, node = 14, scale = 0.25) +
6268
geom_hilight(node = 18, fill = "orange", alpha = 0.3) +

tests/testthat/test-getLevel.R

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
test_that("getLevel works", {
22
## Generate some data
3-
library(TreeSummarizedExperiment)
4-
library(ggtree)
3+
suppressPackageStartupMessages(library(TreeSummarizedExperiment))
4+
suppressPackageStartupMessages(library(ggtree))
55
data(tinyTree)
66
set.seed(1)
77
pv <- runif(19, min = 0.09, max = 0.11)
@@ -107,12 +107,14 @@ test_that("getLevel works", {
107107
message = TRUE),
108108
"The result will be output in the 'keep' column")
109109

110-
expect_error(getLevel(tree = tinyTree, score_data = out,
111-
drop = "pvalue > 0.05",
112-
score_column = "pvalue", node_column = "node",
113-
get_max = FALSE, parent_first = TRUE,
114-
message = TRUE),
115-
"'drop' must be or evaluate to logical")
110+
expect_message(expect_message(
111+
expect_error(getLevel(tree = tinyTree, score_data = out,
112+
drop = "pvalue > 0.05",
113+
score_column = "pvalue", node_column = "node",
114+
get_max = FALSE, parent_first = TRUE,
115+
message = TRUE),
116+
"'drop' must be or evaluate to logical"),
117+
"Preparing"), "Dropping")
116118

117119
## Check that function works as expected for valid input
118120
## -------------------------------------------------------------------------
@@ -186,21 +188,25 @@ test_that("getLevel works", {
186188
expect_equal(final$node[final$keep], c(1, 2, 3, 6, 7, 8, 9, 10, 18))
187189

188190
## Search for the highest value, don't filter, parent_first = FALSE
189-
final <- getLevel(tree = tinyTree, score_data = out,
190-
drop = pvalue > 1, score_column = "pvalue",
191-
node_column = "node", get_max = TRUE,
192-
parent_first = FALSE, message = TRUE)
191+
suppressMessages({
192+
final <- getLevel(tree = tinyTree, score_data = out,
193+
drop = pvalue > 1, score_column = "pvalue",
194+
node_column = "node", get_max = TRUE,
195+
parent_first = FALSE, message = TRUE)
196+
})
193197
expect_s3_class(final, "data.frame")
194198
expect_equal(nrow(final), nrow(out))
195199
expect_equal(final$node, out$node)
196200
expect_equal(final$pvalue, out$pvalue)
197201
expect_equal(final$node[final$keep], c(1, 2, 3, 6, 7, 8, 9, 10, 18))
198202

199203
## Search for the highest value, don't filter, parent_first = FALSE
200-
final <- getLevel(tree = tinyTree, score_data = out,
201-
score_column = "pvalue",
202-
node_column = "node", get_max = TRUE,
203-
parent_first = FALSE, message = TRUE)
204+
suppressMessages({
205+
final <- getLevel(tree = tinyTree, score_data = out,
206+
score_column = "pvalue",
207+
node_column = "node", get_max = TRUE,
208+
parent_first = FALSE, message = TRUE)
209+
})
204210
expect_s3_class(final, "data.frame")
205211
expect_equal(nrow(final), nrow(out))
206212
expect_equal(final$node, out$node)

tests/testthat/test-infoCand.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test_that("infoCand works", {
2-
library(TreeSummarizedExperiment)
2+
suppressPackageStartupMessages(library(TreeSummarizedExperiment))
33
## Generate example data
44
data(tinyTree)
55
set.seed(2L)

tests/testthat/test-medianByClusterMarker.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that("medianByClusterMarker works", {
22
## Generate some data
3-
library(SummarizedExperiment)
3+
suppressPackageStartupMessages(library(SummarizedExperiment))
44
set.seed(1)
55
count <- matrix(rpois(n = 1000, lambda = 10), nrow = 100)
66
colnames(count) <- paste0("mk", 1:10)

tests/testthat/test-nodeResult.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
test_that("nodeResult works", {
2-
library(TreeSummarizedExperiment)
2+
suppressPackageStartupMessages(library(TreeSummarizedExperiment))
3+
suppressPackageStartupMessages(library(GenomeInfoDb))
34
## Generate some example data - DA
45
da_lse <- readRDS(system.file("extdata", "da_sim_100_30_18de.rds",
56
package = "treeclimbR"))
@@ -17,12 +18,14 @@ test_that("nodeResult works", {
1718
ds_se <- aggDS(TSE = ds_tse, assay = "counts", sample_id = "sample_id",
1819
group_id = "group", cluster_id = "cluster_id", FUN = sum)
1920
})
20-
ds_res <- runDS(SE = ds_se, tree = colTree(ds_tse), option = "glmQL",
21-
group_column = "group", contrast = c(0, 1),
22-
filter_min_count = 0, filter_min_total_count = 1,
23-
design = model.matrix(~ group, data = colData(ds_se)),
24-
filter_min_prop = 0, min_cells = 5, message = FALSE,
25-
legacy = FALSE)
21+
suppressMessages(expect_message({
22+
ds_res <- runDS(SE = ds_se, tree = colTree(ds_tse), option = "glmQL",
23+
group_column = "group", contrast = c(0, 1),
24+
filter_min_count = 0, filter_min_total_count = 1,
25+
design = model.matrix(~ group, data = colData(ds_se)),
26+
filter_min_prop = 0, min_cells = 5, message = TRUE,
27+
legacy = FALSE)
28+
}, "0 nodes are ignored"))
2629

2730
## Check that function returns error with invalid input
2831
## -------------------------------------------------------------------------

0 commit comments

Comments
 (0)