60

Hi I have the following markdown chunk:

```{r, echo=FALSE,warning=FALSE,message=FALSE,error=FALSE}
lapply(obj,function(x) plot(x,main="some plot") box() axis(1,at=seq(0,25,by=1))
```

The output is multiple plots. However I also get the console message in the pdf document underneath the plots.

<Plot 1> nice plot 1!
<Plot 2> nice plot 2!

-- nasty horrible console output
## [[1]] 
01.2882829 

## [[2]]
120.29393933

I have tried echo/warning/error/message = FALSE, but neither of these suppress the console output

please help!

brucezepplin
  • 9,202
  • 26
  • 76
  • 129

6 Answers6

58

try this:

{r, echo=FALSE,results='hide',fig.keep='all'}
lapply(obj,function(x) plot(x,main="some plot") box() axis(1,at=seq(0,25,by=1))
Pablo Figueroa
  • 691
  • 1
  • 5
  • 7
27

Wrapping any object in invisible will prevent automatically printing it.

You should be able to use

invisible(lapply(obj,function(x) plot(x,main="some plot")))

However the fact that echo=FALSE doesn't work suggests that there might be something else going on.

shadowtalker
  • 12,529
  • 3
  • 53
  • 96
  • 7
    To add some info, this is the **only** option that worked for me too. **Any** combination of `echo=FALSE, message=FALSE, results='hide'` (including all of them together) did **not** work for me. – alelom Dec 22 '19 at 14:43
20

These are the options that worked for me:

echo=FALSE, message=FALSE, results='hide'
suknat
  • 335
  • 2
  • 7
11

I was having this problem as well in my R notebook and echo=FALSE didn't do anything. However message=FALSE does.

```{r, message=FALSE}
Chris
  • 676
  • 5
  • 20
9

Simply having ```{r, results = 'hide'} or ```{r, results = FALSE} for your chunk options suppresses R output but not warnings, messages or errors. No extra functions are needed.

More details can be found here. https://yihui.org/knitr/options/#text-output

Levi Baguley
  • 646
  • 1
  • 11
  • 18
8

Try this,

It will hide the errors, warning, code, and console output. It will show only the graphs.

{r, echo=FALSE,warning=FALSE,message=FALSE,error=FALSE, results='hide',fig.keep='all'}
lapply(obj,function(x) plot(x,main="some plot") box() axis(1,at=seq(0,25,by=1))

Later you can export it to HTML which will be neat and readable

Taazar
  • 1,545
  • 18
  • 27
Naveen Kumar
  • 277
  • 4
  • 5