ComplexHeatmap icon indicating copy to clipboard operation
ComplexHeatmap copied to clipboard

UpSet Plot annotation causing an error when scoping manually

Open czackl opened this issue 3 years ago • 2 comments

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

czackl avatar Sep 26 '22 14:09 czackl

@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.

jokergoo avatar Sep 28 '22 14:09 jokergoo

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!

federicomarini avatar Sep 28 '22 14:09 federicomarini

Same error thanks for reporting!

ShinyFabio avatar Oct 12 '22 07:10 ShinyFabio