ComplexHeatmap icon indicating copy to clipboard operation
ComplexHeatmap copied to clipboard

Issue with tibble with HeatmapAnnotation using "df" parameter

Open simoncmo opened this issue 1 year ago • 1 comments

Hi found a small bug like behavior in the HeatmapAnnotation function when supplying annotation with "df" parameter in HeatmapAnnotation function

df = data.frame(
    Group = rep(c('A','B'), each = 10),
    Type = sample(c('Tyep1','Type2'), 20, replace = TRUE)
)
# This works fine
HeatmapAnnotation(df = df)

# This causes issue
# Error in attributes(.Data) <- c(attributes(.Data), attrib) : 
#  'names' attribute [20] must be the same length as the vector [1]
HeatmapAnnotation(df = as_tibble(df))

The error message wasn't really helpful to know that the data type is the reason. And since I (and perhaps people using tidyverse language) have been using tibble and data.frame interchangeably
I was not expecting this could have cause the issue and spend quite some time checking what's wrong.

Think I would share this in case others also run into similar issue.

Thanks!

Simon

simoncmo avatar Apr 05 '23 17:04 simoncmo

I don't use tidyverse in my work so I missed it.

The reason is tibble does not degenerate into a vector when only one column is selected, e.g.

tb = as_tibble(df)
tb[, "Group"]

still gives a one-column table.

Now I convert a tibble (or other data frame like data structures) all to a data.frame. You can update the package from GitHub.

jokergoo avatar Apr 13 '23 10:04 jokergoo