Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing horizontal scroll bar in R Markdown HTML code chunks and output

How can I make my knitted .Rmd document not wrap code when producing an HTML document? Whenever I knit my file I get output like the following:

Not what I want...

You can see that the first line containing a cbind call is wrapped. This was produced by the following Rmd code. Basically, I'd like to see the resultant HTML file look like it does here on StackOverflow (i.e. with a horizontal scroll bar).

---
title: "Title"
author: "Author"
date: "March 25, 2016"
output: html_document
---

```{r}
myveryveryveryveryverylongvariablenameanditsdataaaaaaaaaaaaaaaaaaaaaaaaaaa <- cbind(iris, iris, iris, iris, iris, iris, iris)
head(myveryveryveryveryverylongvariablenameanditsdataaaaaaaaaaaaaaaaaaaaaaaaaaa )
```

Then separately, how can I do this for the text output on the second line? I've tried options(width=...) but this only seems to jarble up the output more. I'd like to it also look just as it does here on StackOverflow (no wrapping, with horizontal scroll bar):

  Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal.Length Sepal.Width Petal.Length Petal.Width
1          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2  setosa          5.1         3.5          1.4         0.2
2          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2  setosa          4.9         3.0          1.4         0.2
3          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2  setosa          4.7         3.2          1.3         0.2
4          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2  setosa          4.6         3.1          1.5         0.2
5          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2  setosa          5.0         3.6          1.4         0.2
6          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4  setosa          5.4         3.9          1.7         0.4
like image 326
Jeff Keller Avatar asked Mar 26 '16 02:03

Jeff Keller


1 Answers

Another alternative to both answers - write the css after your YAML header using html:

<style>
pre {
  white-space: pre-wrap;
  background: #F5F5F5;
  max-width: 100%;
  overflow-x: auto;
}

</style>
like image 175
GISHuman Avatar answered Sep 26 '22 14:09

GISHuman