Where are the images gone after knitr/rmarkdown?

1,242 views
Skip to first unread message

Dieter Menne

unread,
May 13, 2016, 5:07:36 AM5/13/16
to knitr
I might  have changed some settings, or maybe it has to do with my switch to Windows 10, or a more recent version of knitr (using 1.13)

When I knit in RStudio, the folder with the images turns up during compile, but is deleted on completion.

What can I do to keep the images?

output:
  bookdown::html_document2:
    css: GastFuncReport.css
    fig_caption: yes
    fig_height: 4.2
    fig_width: 6.2
    mathjax: default
    number_sections: no
    theme: cosmo
    toc_float: TRUE
    toc: yes


Yihui Xie

unread,
May 14, 2016, 3:32:57 AM5/14/16
to Dieter Menne, knitr
By "images folder", do you mean the R plots directory (like
foo_files/figure-html/) or your own images folder? A minimal
reproducible example with sessionInfo() is always better than verbal
description.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
> --
> You received this message because you are subscribed to the Google Groups
> "knitr" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to knitr+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dieter Menne

unread,
May 14, 2016, 3:54:40 AM5/14/16
to knitr, menne...@googlemail.com
Any file will do. It creates a subfolder a_file during build, which is deleted after a successful build. I need the images for separately for publication, and could retrieve it from the folder in (earliery versions)/(my old settings which I might have changed) <- pick the right alternative.


---
title: "Untitled"
output: html_document
---

```{r pressure, echo=FALSE}
plot(pressure)
```

Yihui Xie

unread,
May 14, 2016, 4:09:06 AM5/14/16
to Dieter Menne, knitr
I see. You can need self_contained to be FALSE, e.g.

---
title: "Untitled"
output:
html_document:
self_contained: no
---

```{r pressure, echo=FALSE}
plot(pressure)
```

Or if you do want a self-contained HTML file, keep_md: yes may also
preserve the figure directory.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name


Dieter Menne

unread,
May 14, 2016, 4:18:34 AM5/14/16
to knitr, menne...@googlemail.com
keep_md  works and is ok (even if a bit confusing, I normally use that for testing bad cases only).

self_contained: no is not so good, because I alway need self_contained to mail a report.

This has changed, because I have many old reports without keep_md that keep the images. Is it really useful? Images are almost always needed separately for people writing the paper.


Yihui Xie

unread,
May 14, 2016, 4:31:15 AM5/14/16
to Dieter Menne, knitr
I don't remember we changed anything that could lead to this issue
recently. Anyway, if you are writing a paper, you probably want the
PDF output (pdf_document with keep_tex: yes) instead of HTML.

Another possibility is rmarkdown::render(clean = FALSE) so all
intermediate files will be preserved, but you cannot specify clean =
FALSE in the YAML metadata of an R Markdown document.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name


Dieter Menne

unread,
May 14, 2016, 4:47:55 AM5/14/16
to knitr, menne...@googlemail.com
>>. Anyway, if you are writing a paper, you probably want the PDF output (pdf_document with keep_tex: yes) instead of HTML.

I used to write Sweave latex for more than 10 years, but do not use it for  reporting any longer. Papers in medicine are always written in Word, based on the statistical report because of the many co-editors involved, that's why the images are needed and pdf is not accepted.

Using HTML for the raw-report output proved to be helpful, because tables can be easily copy-pasted from Html into Word. Copying tables from pdf are a horror.

Anyway, keep_md is ok, but if you insist on deletion by default (why?), it would be good to have the "figure-keep" in the documentation.


Yihui Xie

unread,
May 14, 2016, 4:53:32 AM5/14/16
to Dieter Menne, knitr
I don't insist on deletion. This has been what self_contain = FALSE
does from the very beginning of rmarkdown. I understand it can be
useful to preserve the figure directory, and keep_md = TRUE is nearly
the same as your figure_keep = TRUE (the only difference is the extra
.md output file).

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name


Reply all
Reply to author
Forward
0 new messages