10

I'm analyzing some data and would like to do a Simpsons paradox on R. I've installed the Simpsons package and loaded the library. Here is an example based on the package documentation:

---
output: html_document
---
```{r}
library(Simpsons)
#generating data 
Coffee1=rnorm(100,100,15)
Neuroticism1=(Coffee1*.8)+rnorm(100,15,8)
g1=cbind(Coffee1, Neuroticism1)
Coffee2=rnorm(100,170,15)
Neuroticism2=(300-(Coffee2*.8)+rnorm(100,15,8))
g2=cbind(Coffee2, Neuroticism2)
Coffee3=rnorm(100,140,15)
Neuroticism3=(200-(Coffee3*.8)+rnorm(100,15,8))
g3=cbind(Coffee3, Neuroticism3)
data2=data.frame(rbind(g1,g2,g3))
colnames(data2) <- c("Coffee","Neuroticism")

example <- Simpsons(Coffee,Neuroticism,data=data2) 
plot(example)
```

This is returning a plot with 3 clusters (exactly what I need). However, when I Knit the Rmd file to HTML, I'm getting a lot of equals signs (======) with a percentage next to it like a loading grid which I would like to remove from my final output.

enter image description here

Michael Harper
  • 14,721
  • 2
  • 60
  • 84
Mtra
  • 201
  • 4
  • 10
  • Please give a [mcve]. See [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269/4996248) for what this would mean in R. – John Coleman Oct 16 '18 at 11:40
  • It seems that you need to modify [knitr chunk options](https://yihui.name/knitr/options/#text-results), try setting `message = FALSE`. – pogibas Oct 16 '18 at 11:43
  • I have edited the question to show you how to include a minimal example. Hope that helps you how to make it easy for other people to help as this can be run by people who want to help to reproduce your error. – Michael Harper Oct 16 '18 at 11:56
  • 1
    Thanks Michael that's the exact thing I would like to remove. I've already tried setting message = FALSE but nothing changed – Mtra Oct 16 '18 at 12:03
  • Possible duplicate of [How to suppress all messages in knitr/ Rmarkdown?](https://stackoverflow.com/questions/26456924/how-to-suppress-all-messages-in-knitr-rmarkdown) – pogibas Oct 16 '18 at 12:04

1 Answers1

7

You can suppress any output messages in R by setting the knitr chunk option. If we wish to hide all code output other than plots, we can use the following solution:

---
output: html_document
---

```{r echo=FALSE, results='hide', fig.keep='all', message = FALSE}
library(Simpsons)
#generating data 
Coffee1=rnorm(100,100,15)
Neuroticism1=(Coffee1*.8)+rnorm(100,15,8)
g1=cbind(Coffee1, Neuroticism1)
Coffee2=rnorm(100,170,15)
Neuroticism2=(300-(Coffee2*.8)+rnorm(100,15,8))
g2=cbind(Coffee2, Neuroticism2)
Coffee3=rnorm(100,140,15)
Neuroticism3=(200-(Coffee3*.8)+rnorm(100,15,8))
g3=cbind(Coffee3, Neuroticism3)
data2=data.frame(rbind(g1,g2,g3))
colnames(data2) <- c("Coffee","Neuroticism")

example <- Simpsons(Coffee,Neuroticism,data=data2) 
plot(example)
```

I would note that this package seems to print out a lot more content that most packages, and therefore the combination of options are quite long.

An easier method would probably be to move the plot to a separate chunk and have all the analysis run before it. The include argument can be used to suppress all outputs, but this includes plots, hence why we must use two chunks:

```{r, include = FALSE}
# your code to build model
```

```{r}
plot(example)
```

Check out the full list of knitr chunk options here

Michael Harper
  • 14,721
  • 2
  • 60
  • 84