I'm trying to get the PNG plots from knitr output to write to disk as separate files without doing it manually.
What I tried
The dev = 'png' setting from http://gforge.se/2014/01/fast-track-publishing-using-knitr-part-iii/ (also mentioned in this question)
self_contained: no from knitr: include figures in report *and* output figures to separate files.
Neither worked. The folder the knitting process ran in has no extra files, and the HTML document has base64 embedded images in its source.
Environment
RStudio 0.99.903
R 3.2.3
knitr 1.15.1
MWE: The RStudio RMarkdown file, with abovementioned options added:
---
title: "Untitled"
output: html_document
self_contained: no
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(dev="png",
dev.args=list(type="cairo"),
dpi=96)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
self_contained is an option for html_document, not a top-level YAML setting. The document below works using just that. PNG is the default figure type, so you don't need to specify that.
---
title: "Untitled"
output:
html_document:
self_contained: no
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Related
When starting RStudio, this error appears. I can run several commands, but I can't compile anything in Rmarkdown. Does anyone know how I can fix it?
The error does not appear when typing a path to read from the file. It even appears when I try to compile an empty file in RMarkdown.
The error even appears with the default example script in RMarkdown.
---
title: "Untitled"
author: "Autor"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
There is currently a thread for how to Wrap text around plots in Markdown but this is only for knitting to HTML. I need to be able to place text next to a plot and output to a word document.
---
title: "Untitled"
author: "Your Name"
date: "May 27, 2020"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
```{r pressure, echo=FALSE, out.width= "65%", out.extra='style="float:right; padding:10px"'}
plot(pressure)
```
This is an R Markdown document. Markdown is a simple formatting syntax for authoring
HTML, PDF, and MS Word documents. For more details on using R Markdown see
<http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both
content as well as the output of any embedded R code chunks within the document. You can
embed an R code chunk like this:
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing
of the R code that generated the plot.
Please advise.
I tried to create a RMarkdown file, with the default template by RStudio like below:
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
When I clicked knit, it only rendered a raw html file like below, as if no css is applied to the html.
How to fix it?
I was told to write a report in R Markdown with the following template:
---
title: "Data Dictionary"
output: github_document
date: "Last Updated: `r format(Sys.time(), '%d, %B, %Y at %H:%M')`"
---
I want to use readthedown theme from rmdformats package, however I could not find a tutorial on how to do so properly. My question is, is it possible to use a theme with this template? Any help would be appreciated!
Assuming you already have installed the package, remotes::install_github("juba/rmdformats"), just pass rmdformats::readthedown to the output YAML:
---
title: "Untitled"
date: "Last Updated: `r format(Sys.time(), '%d, %B, %Y at %H:%M')`"
output: rmdformats::readthedown
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Does anybody know why R markdown generates excessive white space above each plot and how can I fix that ? Is there a knitr option to be included ? Or any chunk option maybe ?
I've provided 3 images at the bottom of this post so that you can see what I mean.
Haven't used any other chunk option than echo, warning and message and about the plot it is a basic ggplot.
Let me know in the comments if I need to provide any code example of my chunks for a better view.
Edit: here's a simple rmarkdown file generating the same excessive white space above ggplots.
---
title: "Untitled"
author: "Razvan Cretu"
date: "January 9, 2019"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r import, echo=FALSE}
library('ggplot2')
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
ggplot(cars, aes(speed, dist))+
geom_line()
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.