raivokolde / pheatmap

Pretty heatmaps
225 stars 83 forks source link

not correctly plotting heatmap (only grey) when object called "as.double.factor" is in the global environment #96

Open PStaus opened 1 year ago

PStaus commented 1 year ago

Thank you for the nice plotting package for heatmaps. When I defined a function called as.double.factor in my global environment the pheatmap function stopped plotting correctly. Here a reproducible example. It seems, that the package uses a function with the same name, but tries to load it from the global environment. I never wrote a package so I am not very firm with working environments.

library("pheatmap")
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 = "")

# Draw heatmaps
pheatmap(test)

as.double.factor<- function(x) {as.numeric(levels(x))[x]}

pheatmap(test)

Best wishes,