1

Below the code for generating a histogram plot with the base plot system in R and converting this via Rmarkdown to a pdf (Latex). I set message=FALSE, warning=FALSE, error=FALSE etc, but still get output from the system. How can I just show the plot??

---
title: "Test"
author: "Me"
date: "Tuesday, September 30, 2014"
output: pdf_document
---

```{r,message=FALSE,warning=FALSE,cache.comments=FALSE,error=FALSE,prompt=FALSE}
par(mfrow=c(2,2))
replicate(4,hist(replicate(1000,mean(rnorm(10000,1,10))),col="slateblue4",
             main="Distribution of the Mean",col.main="steelblue4",
             xlab="Mean",ylab="Count"))
```
New_code
  • 594
  • 1
  • 5
  • 16

1 Answers1

1

This is happening because the output that you are getting on your document is neither a warning, a message nor an error. Those stuff printed is a legit (but undesired) output from replicate() function.

The easiest way out is wrap up the inconvenient replicate (the outer one) with invisible() function. This latter in practice, suppress the output of the expression passed to it, resulting in the desired output.

```{r,message=FALSE,warning=FALSE,cache.comments=FALSE,error=FALSE,prompt=FALSE}
par(mfrow=c(2,2))
invisible(replicate(4,{hist(replicate(1000,{return(mean(rnorm(10000,1,10)))}),col="slateblue4",
             main="Distribution of the Mean",col.main="steelblue4",
             xlab="Mean",ylab="Count")}))
```

refs to invisible: doc and SO question.

Regards!

Community
  • 1
  • 1
Athos
  • 650
  • 4
  • 10