68
votes

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

2
I think something like fig.width = \\linewidth in the chunk options might help, but I defer to better experts than meSimon O'Hanlon
I'm ok with the figure.width, that can be controlled in my chunk options just fine. The problem is the blocks of text/table output being fixed. Thanks for pointing out the \\linewidth which will be useful in the future.Matt Weller
I suggest you post some reproducible sample code to show how the offending plots are created. Maybe if you look in the help manual for your plotting function there will be some dummy data and code samples you can use? It will probably help a lot.Simon O'Hanlon
It is not the plots which are offending. The figures are printing just how I would like them. It's the TEXT/TABLES which are not using the full width of the screen. I can supply an example if it is really required.Matt Weller

2 Answers

109
votes

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.

13
votes

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

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

```