ComplexHeatmap
ComplexHeatmap copied to clipboard
UpSet Plot annotation causing an error when scoping manually
Hi,
we recently noticed an uncommon behaviour of the UpSet Plot annotation. We solved the issue in our case but it could be beneficial for others as well.
Short summary: When scoping the upset_xxx_annotation function manually the UpSet function will produce an error internally.
Reproducible example:
# sample data from UpSetR
movies <- read.csv(system.file("extdata", "movies.csv", package = "UpSetR"),
header = TRUE, sep = ";")
library(ComplexHeatmap)
m <- make_comb_mat(movies, top_n_sets = 6)
# will produce an error in R>4.2 and a warning in R<4.2
ComplexHeatmap::UpSet(m,
top_annotation = ComplexHeatmap::upset_top_annotation(m, # adding numbers
add_numbers = TRUE,
numbers_gp = grid::gpar(
fontsize = "14",
fontface = "bold"
)
)
)
# works
ComplexHeatmap::UpSet(m,
top_annotation = upset_top_annotation(m,
add_numbers = TRUE,
numbers_gp = grid::gpar(
fontsize = "14",
fontface = "bold"
)
)
)
What is happening
When scoping manually the if statement in line 1412 will contain c("::", "ComplexHeatmap", "upset_top_annotation") and therefore the == comparison will be vectorized. This results in an condition has length 1 and only the first element will be used error/warning depending on the R Version. It can be solved by wrapping the call in any(), so calling it both ways will pass the if statement. All other annotation sides should be handled accordingly.
https://github.com/jokergoo/ComplexHeatmap/blob/b3314e0e261ce7d60aeba589fe061756d998c735/R/Upset.R#L1409-L1418
Greetings! Constantin and @federicomarini
@constantin-zackl and @federicomarini, thank you very much for digging out this problem! I believe there should be many similar things hiding in the source code.
Now it is fixed.
Awesome, thanks a lot!
AFAIK, it used to be a warning, and became an error in the latest release of R (>= 4.2.0). Even better if you did a complete check of other possible locations where this might become a problem!
Same error thanks for reporting!