Skip to content

Commit 26a5e0b

Browse files
brandonlukasclaude
andcommitted
Restore ht_opt$annotation_use_raster for internally built annotations
UpSet(), oncoPrint() and pheatmap() construct HeatmapAnnotation() internally and never pass `use_raster`, so the global option is the only way to rasterize those annotations. Declared as a plain nullable option to match `annotation_border`, which also allows resetting it to NULL. Add a test covering the internal path and argument precedence. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3c939cf commit 26a5e0b

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

R/HeatmapAnnotation-class.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ HeatmapAnnotation = function(...,
151151

152152
fun_args = names(as.list(environment()))
153153

154+
# annotations built inside wrapper functions (oncoPrint(), UpSet(), pheatmap())
155+
# never get `use_raster` passed to them, so the global option is the only way
156+
# to rasterize those
157+
if(missing(use_raster) && !is.null(ht_opt$annotation_use_raster)) {
158+
use_raster = ht_opt$annotation_use_raster
159+
}
160+
154161
verbose = ht_opt$verbose
155162

156163
.Object = new("HeatmapAnnotation")

R/global.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ ht_opt = setGlobalOptions(
209209
.value = FALSE
210210
),
211211
"validate_names" = TRUE,
212+
annotation_use_raster = list(
213+
.value = NULL),
212214
raster_temp_image_max_width = 30000,
213215
raster_temp_image_max_height = 30000,
214216
COLOR = c("blue", "#EEEEEE", "red")

tests/testthat/testthat-annotation-raster.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ test_that("raster parameters are passed down to single annotations", {
1111
expect_false(ha@anno_list[["foo"]]@raster_param$use_raster)
1212
})
1313

14+
# annotations built inside UpSet(), oncoPrint() and pheatmap() are never given a
15+
# `use_raster` argument, so `ht_opt$annotation_use_raster` is the only way to
16+
# rasterize them
17+
test_that("ht_opt$annotation_use_raster reaches internally built annotations", {
18+
on.exit(ht_opt$annotation_use_raster <- NULL)
19+
20+
m = make_comb_mat(list(a = 1:5, b = 3:8, c = 4:10))
21+
expect_false(UpSet(m)@top_annotation@anno_list[[1]]@raster_param$use_raster)
22+
23+
ht_opt$annotation_use_raster = TRUE
24+
expect_true(UpSet(m)@top_annotation@anno_list[[1]]@raster_param$use_raster)
25+
26+
# an explicit argument still wins over the global
27+
expect_false(HeatmapAnnotation(foo = 1:10, use_raster = FALSE)@anno_list[["foo"]]@raster_param$use_raster)
28+
})
29+
1430
# the graphics drawn by `draw_fun` are in absolute units, so the rasterized
1531
# result must occupy the same area no matter how large the temporary image is
1632
test_that("rasterized annotation does not shrink when raster_quality increases", {

0 commit comments

Comments
 (0)