1

I am trying to generate a plot using heatmap.2 and print to a pdf_document using Rmarkdown.

Whether I call heatmap.2 from the console or in an .Rmd, the plot appears perfectly exactly as I want it. But additionally, I receive the error message:

## Error in plot.new(): figure margins too large

I can force knitr to continue processing using error=TRUE, but the error message is still printed. I also have set

echo=FALSE, warning=FALSE, message=FALSE

which I thought would suppress the message, but it doesn't. I have tried using invisible() as per this question, but it seems to do nothing.

I have also tried "fixing" the error by adjusting my plot parameters in heatmap.2 with no success-- it seems to complain when one of my columns in lhei is too skinny. Since the plot looks fine, I am not worried about it unless there is no other way to suppress this error message.

How can I suppress this error message in my Rmarkdown pdf?

Community
  • 1
  • 1
Jeff
  • 12,147
  • 10
  • 51
  • 87
  • 1
    I can't test this without seeing your code / markdown script, but you could try wrapping your plot call in `try(...,silent=TRUE)`, e.g. `try(,silent=TRUE)`. – nrussell Jan 29 '15 at 18:55
  • It worked! If you want to leave an answer I'll mark it as accepted. – Jeff Jan 29 '15 at 19:09

1 Answers1

2

A pretty robust way of suppressing error messages is to wrap an expression in try(...,silent=TRUE). As a general example, if we use the following code to set up a plot layout

plotIDs <- matrix(c(1:16), 4, 4, byrow = T)
layout(plotIDs, widths = c(0.5,1,1,1,1), heights = c(0.5,1,1,1,1))

calling frame() afterwards will produce an error:

R> frame()
Error in frame() : figure margins too large

Wrapping this with try, i.e.

R> try(frame(),silent=TRUE)
R> 

will not produce an error message in the console.

nrussell
  • 18,382
  • 4
  • 47
  • 60