I am having knitr to create an output of my statistical analysis along with figures. My analysis has a number of levels that are marked by headers. To get the nice html page with table of contents on the side I use "pander" (pandoc R package) to convert my .md file to html because knitr does not embed table of contents in the html file.
The problem: When I use pander it creates a fixed width page (quite narrow) where my large figures need to be scrolled left and right. Is there any way to resize either .md page width or direct pander to output a page with auto-width settings (adjusting to a any screen width).
I did spend time looking for a solution: either have knitr aromatically embed TOC, embed width parameter into the r code
```{r set-options, echo=FALSE, cache=FALSE}
options(width=600)
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, echo = TRUE, tidy = FALSE, size="small")
```
or adjust pader output paramaters but did not have any luck.
If anyone has a solution to the problem I would really appreciate it.
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 .
Rendering. 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.
The first code chunk: ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` is used to specify any global settings to be applied to the R Markdown script. The example sets all code chunks as “echo=TRUE”, meaning they will be included in the final rendered version.
knitr
does not take care of markdown rendering directly, and you can compile *.md
to *.html
through the markdown
package, for which knitr
has a wrapper function knit2html()
. To get the table of contents, you can add the toc
option to markdown::markdownToHTML()
, e.g.
library(knitr)
knit2html('foo.Rmd', options = c('toc', markdown::markdownHTMLOptions(TRUE)))
To avoid scrolling, You can use out.width
and out.height
to fix width and height of the plot in the final output file.
```{r fig.width=7, fig.height=6,out.width=250,out.height=400}
plot(cars)
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With