Matt Weller
Matt Weller

Reputation: 2764

Adjust the output width of R Markdown HTML output

I am producing an HTML output but I am having issues with the output width of R code output.

I'm able to adjust the figure width with no difficulty but when I try to write a data table or the factor loadings, R is outputting at a fixed width which is only about a third of my screen width. This results in the columns of the table being split up rather than all of the columns displayed in a single table.

Here is a reproducible example:

---
output: html_document
---

# Title

```{r echo = FALSE, fig.width=16, fig.height=6}
x = matrix(rnorm(100),ncol=10)
x
plot(x)
```

enter image description here

Upvotes: 89

Views: 98486

Answers (2)

HBat
HBat

Reputation: 5702

Also, you can temporarily change the local R options for a code chunk:

```{r my-chunk, R.options = list(width = SOME-BIG-VALUE)}

```

Upvotes: 35

A5C1D2H2I1M1N2O1R2T1
A5C1D2H2I1M1N2O1R2T1

Reputation: 193667

Add this at the start of your document:

```{r set-options, echo=FALSE, cache=FALSE}
options(width = SOME-REALLY-BIG-VALUE)
```

Obviously, replace SOME-REALLY-BIG-VALUE with a number. But do you really want to do all that horizontal scrolling?

Your output is probably being wrapped somewhere around 80 characters or so.

Upvotes: 122

Related Questions