Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save Rmarkdown's report tables and figures to file

Tags:

r

r-markdown

Simple question:

I have an Rmarkdown script where I generate tables and figures:

---
title: "test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r libraries}
library(knitr)
library(kableExtra)
library(ggplot2)
```


# Table
```{r print.table,warning=FALSE,message=FALSE}
df <- data.frame(id=LETTERS,value=1:26)
knitr::kable(df) %>% kable_styling()
```


# Figure
```{r print.params.table,warning=FALSE,message=FALSE}
ggplot(data=df,aes(x=id,y=value))+geom_point()
```

My question is if there's a way to be able to save the tables and figures to files (e.g., csv and pdf, respectively) from the html report?

What I mean by that is suppose I'm sending this html report to a collaborator and he want to have a separate copy of the tables and figures without having to write any line of code. Does Rmarkdown or knitr enable that in the html report in a form of a button or do I have to programmatically save these to files?

like image 274
dan Avatar asked Jun 23 '17 00:06

dan


1 Answers

If you add keep_md option then image files are kept in your directory (like in "xxx_file" folder), which you can send to your colleague. But I don't think there is an option for tables.

---
title: "test"
output: 
  html_document:
      keep_md: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r libraries}
library(knitr)
library(kableExtra)
library(ggplot2)
```


# Table
```{r print.table,warning=FALSE,message=FALSE}
df <- data.frame(id=LETTERS,value=1:26)
knitr::kable(df) %>% kable_styling()
```


# Figure
```{r print.params.table,warning=FALSE,message=FALSE}
ggplot(data=df,aes(x=id,y=value))+geom_point()
```
like image 77
Kota Mori Avatar answered Oct 24 '22 15:10

Kota Mori