Search code examples
r-markdownknitr

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


Solution

  • 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.