Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 889
Matt Weller Avatar asked Mar 13 '13 12:03

Matt Weller


People also ask

How do I change the output size in R Markdown?

To change the output size you can use the corresponding LaTeX commands, set just before the code junk. The smallest option would be \tiny . For a full overview consider e.g. this. After the code junk it's important to set back to the size you used before, e.g. \normalsize .

How do I convert R Markdown to HTML?

To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.

What does Tabset fade do?

tabset-fade} . The tabs within that group are created by level 3 headers ( ### ). To close down the tabbed section, it is necessary to introduce a new level 1 or 2 header. Please note it is VERY IMPORTANT to include a blank line before a new tabbed section begins.

How do I set the maximum width of a Rmarkdown document?

Put this at the top (but below the YAML) of your rmarkdown document: Don't put it in a chunk but as plain text. It should set the max-width of the content area to 1800px.

What can you do with R Markdown?

You can also build books, websites, and interactive documents with R Markdown. Each output format is implemented as a function in R. You can customize the output by passing arguments to the function as sub-values of the output field.

Why is the text output from R code too wide?

Sometimes the text output printed from R code may be too wide. If the output document has a fixed page width (e.g., PDF documents), the text output may exceed the page margins. See Figure 5.1for an example.

Why does my text output exceed the page margins in R?

If the output document has a fixed page width (e.g., PDF documents), the text output may exceed the page margins. See Figure 5.1for an example. The R global option widthcan be used to control the width of printed text output from some R functions, and you may try a smaller value if the default is too large.


2 Answers

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.

like image 156
A5C1D2H2I1M1N2O1R2T1 Avatar answered Oct 09 '22 04:10

A5C1D2H2I1M1N2O1R2T1


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

```{r my-chunk, R.options = list(width = SOME-BIG-VALUE)}  ``` 
like image 45
HBat Avatar answered Oct 09 '22 02:10

HBat