Thank you for the response. Good to understand this difference.
I found the issue. I added a line :
donotdisplay <- device.off()
after line (1) and before line (2) in my heatmap.Rmd code. And this weird plot stopped showing.
I do not understand why the plot in RSession's memory was getting plotted randomly before. But switching off the device worked. So I'd still say this is a bug?? I will try to mock up a small separate code to replicate this issue.
But, thanks again!
Pradeep