4

I have a chunk of code I don't want to split up in my .rmd file that I'm knitting in RStudio.

My global options are:

{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, autodep = T, message = FALSE, warnings = FALSE, cache=TRUE, messages=FALSE)

Even my chunk option is:

{r section025, message=FALSE, warning=FALSE}
code here

And the PDF output shows the following in the middle of the page where I have saved an image out in my code:

## pdf 
## 2

I seem to have used all the suppression options, so I cannot figure out why this still appears. Thoughts appreciated.

JSON C11
  • 11,272
  • 7
  • 78
  • 65
M. Elliott
  • 109
  • 1
  • 9
  • are you creating a separate pdf or is this something embedded into your rmd? if the latter, you do not need `dev.off`. anyway the output you see is just regular output--no `message`, `warning`, or error, so you can suppress this (and still see the plot) with `{r, results='hide'}` – rawr Mar 25 '16 at 21:13
  • I believe I still need `dev.off`, as I'm just creating an image to put into the document elsewhere, not showing the image there. `results='hide'` doesn't work because there are other tables in the chunk that I need in the output. For now, I will just break up into a whole bunch of chunks instead of leaving as one. – M. Elliott Mar 25 '16 at 21:45
  • There are ways to use results from a previous chunk in a later chunk, this would be preferable to creating an external file in a chunk that is outputting a table to the prepared document. It would help us to help you if you provide a **[minimal](http://stackoverflow.com/help/mcve)** and **[reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)** question. – r2evans Mar 26 '16 at 03:53
  • Sorry - it's not related to `autodep` from a prior chunk if I"m trying to do it all within one section. I couldn't find a solid around other than doing a separate chunk with `autodep=T`, which is fine. Thanks for the input. – M. Elliott Mar 26 '16 at 15:04

2 Answers2

4

I got a similar problem. My solution was to use dev.off within invisible()

Claude
  • 41
  • 4
4

send the result of dev.off() to a garbage variable

whatever <- dev.off()
splaisan
  • 845
  • 6
  • 22