I would like to adjust the trace argument (line divisions visible in the heatmap) in the code of the heatmap.2 function in R, to ultimately remove the dotted lines, but keep the solid lines. More generally I would also like to learn how to adjust user-defined functions.
I found a suggestion on how to do this here: https://support.bioconductor.org/p/42819/.
However, when I adjust anything in the code (e.g. line type for the trace argument)(either using the function fix() or making a new function with another name, but with the same code), I start getting errors that certain functions are not found in R, such as invalid() and plot.dendrogram(). I installed separate packages for these functions, but that does not solve the problem. Even worse, when using the fix() approach, heatmap.2 keeps getting these errors from that point, even if I undo the code change, and I have to re-install the gplots package.
I don't understand how the heatmap.2 function runs them without problem, but when I adjust the code, these underlying functions are not found anymore.
TLDR: How can I adjust functions safely in R, particularly the heatmap.2 function?
Any help would be appreciated.
Normally you should be able to just get all code by running heatmap.2
without any options (it's a lot) and then copy it and assign it to a new function as suggested in your bioconductor. That is the generally accepted way to do it. I don't think the fix()
approach is desired here because it indeed overwrites the object in your workspace (i.e. unless you clear your workspace a changed heatmap.2
will take precedence).
For your convenience, I have created a gist that contains the normal code and assigns it to a new function. I would paste this in a new file (e.g. heatmap3.R) in your working directory and source("heatmap3.R")
in your current analysis script. Of course you may need to edit this file, I already commented out lines 345-348 and 359-362 which I think are responsible for the dashed lines. This should be the general strategy when trying to adapt existing functions (unless they are S4/S3 or internal functions, then stuff gets more tricky)
<script src="https://gist.github.com/FMKerckhof/9dd986191570bec2d68fa50122c22e3a.js"></script>