Skip to content

dir with figure is deleted in multi format generation #1503

Closed

Description

@cderv

From a question on Rstudio community, it seems that default behaviour for html_document is to delete the whole files_dir of the form *_files even if something else from other format is there.

I tried to come up with a reprex for this. See below

  • github_document generate a figure that lives in a figure-gfm folder, required to use with the md file generated
  • html_document by default is self_contained=TRUE, so cleaning is activated (unless clean = FALSE in render. The cleaning process suppress the whole files_dir , *including the figure-gfm
  • using output format "all" to generate both format shows that everything is deleted and the png file for the plot does not exist anymore for the github_document format.
# create temporary directory to work in for example
dir_temp <- fs::path_temp("rmd")
fs::dir_create(dir_temp)

# create test rmd file
test_rmd <- fs::file_temp("test", dir_temp, ext = ".Rmd")
writeLines(c('---
title: "R Notebook"
output:
  github_document: default
  html_document:
      self_contained: true
---',
'This is a test file

```{r cars-plot, fig.cap = "plot of cars"}
plot(cars)
```

```{r mean-speed}
mean_speed <- mean(cars$speed)
```
'), test_rmd)

fs::dir_ls(dir_temp)
# creating plot file in a new folder
rmarkdown::render(test_rmd, "github_document")
fs::dir_ls(dir_temp, regexp = "_files", recursive = TRUE)

# without clean the dir is here
rmarkdown::render(test_rmd, "html_document", clean = FALSE)
fs::dir_ls(dir_temp, regexp = "_files", recursive = TRUE)

# with default clean = TRUE, the whole dir is deleted, even the file from github_document format.
rmarkdown::render(test_rmd, "html_document")
fs::dir_ls(dir_temp, regexp = "_files", recursive = TRUE)
fs::dir_ls(dir_temp, recursive = TRUE)

# no folder for github document containing the image
rmarkdown::render(test_rmd, "all")
fs::dir_ls(dir_temp, regexp = "_files", recursive = TRUE)
fs::dir_ls(dir_temp, recursive = TRUE)

# both folder are present
rmarkdown::render(test_rmd, "all", clean = FALSE)
fs::dir_ls(dir_temp, regexp = "_files", recursive = TRUE)
fs::dir_ls(dir_temp, recursive = TRUE)

# clean
unlink(dir_temp, recursive = TRUE)

There are different argument fir a workaround (clean = FALSE, or self_contained: false, change fig_path location) that will prevent that, but seems like an non wanted effect.

What do you think ?

Activity

  1. added this to the v1.12 milestone on Mar 13, 2019
  2. added
    bug
    on Mar 13, 2019
  3. yihui commented on Mar 13, 2019

    @yihui
    Collaborator

    Duplicate of #1472

  4. yihui commented on Mar 13, 2019

    @yihui
    Collaborator

    Should be fixed now. Thanks for the report and the reprex!

  5. added a commit that references this issue on Apr 1, 2019
    528d9e4
  6. cderv commented on Apr 10, 2019

    @cderv
    CollaboratorAuthor

    It seems like this is not fixed. I rerun the reprex and the issue still here. I see where it comes from.
    I can help with a PR if you want.

  7. reopened this on Apr 12, 2019
  8. github-actions commented on Nov 3, 2020

    @github-actions

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

  9. locked as resolved and limited conversation to collaborators on Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions