raivokolde / pheatmap

Pretty heatmaps
225 stars 83 forks source link

More specific error for unexpected data types when adding annotations #86

Open Nelson-Gon opened 2 years ago

Nelson-Gon commented 2 years ago

Hello there,

Thank you for this awesome package. While trying to create a pretty heatmap with annotations, I faced the error

Error in cut.default(a, breaks = 100) : 'x' must be numeric

However, digging into the issue, I noticed that the error was in fact because I was using a tibble instead of a data.frame for the annotation_col argument. A reprex follows below

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
annotation_col = data.frame(
  CellType = factor(rep(c("CT1", "CT2"), 5)), 
  Time = 1:5
)
rownames(annotation_col) = paste("Test", 1:10, sep = "")
pheatmap::pheatmap(test, annotation_col = annotation_col)

The above works as expected. However the following fails with the above error

pheatmap::pheatmap(test, annotation_col = dplyr::as_tibble(annotation_col))

I think it may be more useful in such a case to specify that we expect a data.frame object. I am using pheatmap 1.0.12

Thank you,

NelsonGon