Quick Problem Statement :
R markdown is displaying a plot that I'm not calling in my code. It seems to magically appear out of nowhere.
Background:
I'm using R markdown to display a heatmap I create using ggplot2+plotly, in my report.
The report shows this heatmap correctly.
Here is my Rmarkdown code inside a Rmd file call heatmap.Rmd
...
summarise.heatmap(inpt1, inpt2)
``` ....(1)
```{r echo=FALSE, results = 'asis', message=FALSE} ....(2)
knitr::knit_child('child_report.Rmd', envir=environment(), quiet = TRUE)
In the above code snippet, function summarise.heatmap() outputs a ggplotly object. I've shown the function below. The code then proceeds to call a template Rmd file called child_report.Rmd.
Here is the summarise.heatmap function. (My work prohibits me from showing my original code for security reasons so here is a snippet)
summarise.heatmap <- function(inpt1,inpt2){
...
htmap <- ggplot(data=scores, aes(x=metric,y=Split,fill=dy,text=paste0(round(dy,1)," mV"))) +
geom_tile() +
facet_grid(~Deck, scales = 'free') +
scale_fill_distiller(palette="RdYlBu") +
theme_bw() +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank())
ggplotly(htmap, tooltip="text")
}
The above function is sourced inside the heatmap.rmd file and works correctly.
Finally the heatmap.Rmd is called inside another R script as follows:
rmarkdown::render("heatmap.Rmd",
output_file = paste0(results.folder,
"heatmap_",
inpt1,"-",
inpt2,
".html"))
Here is the heatmap as seen in my rmarkdown report
Problem Statement:
Rmarkdown report in addition to the correct heatmap shows another heatmap that I'm not calling anywhere AT ALL in my code. Report displays this wrong heatmap right after code lines (1) and before (2) shown above.
This second heatmap was generated as part of my development process. So its loaded in memory somewhere. I do not understand how Rmarkdown prints this old heatmap even though there is no call for this in Rmarkdown code.
Interestingly when I click on the "knit" button in my Rstudio, I dont see this issue. In other words, only the correct heatmap that I call in my code, is generated. So it is somehow related to rmarkdown::render call from my R script (shown above)
What I've tried so far :
- Since the knit button works but the render call shows this issue, I'm strongly inclined to think this is a bug.
- However I tried printing the subsequent lines of code shown in (2). They seem to be working correctly.
Need help