Skip to content

rmarkdown creates _files directory not cleared #1553

Closed

Description

@wxli0

Hello,

I was playing with rmarkdown::render() function. After that, I found knit in rmarkdown always created an empty "_files" directory, which I do not want. Is there any commands that can help me get rid of this directory automatically? I have attached the all the render commands I have tried.

# output_dir <- "result"
# render()
# rmarkdown::render("6_1p_CSC05a_onset.Rmd", output_file = "result/6_1p_CSC05a_onset.pdf")
# rmarkdown::render('6_1p_CSC05a_onset.Rmd', 
#                   output_file='6_1p_CSC05a_onset.md')
# rmarkdown::render("6_1p_CSC05a_onset.Rmd")
# knit("doc.Rmd", "papers/doc.md")
# knit("6_1p_CSC05a_onset.Rmd", "result/6_1p_CSC05a_onset.md")
# opts_knit$set(output.dir="result")
# must place in the folder as iRaster.R due to source(...)
# rmarkdown::render("6_1p_CSC05a_onset.Rmd", output_format = "all",  clean = TRUE)

In my case, it always created 6_1p_CSC05a_onset_files folder in the same folder as 6_1p_CSC05a_onset.pdf. Any help would be appreciated!

Activity

  1. added
    bug
    on Mar 19, 2019
  2. added this to the v1.13 milestone on Mar 19, 2019
  3. wxli0 commented on Apr 8, 2019

    @wxli0
    Author

    Is there any update on this issue?

  4. olyerickson commented on Apr 9, 2019

    @olyerickson

    It is normal for Markdown to create the empty "_files" directory, but it usually cleans up after itself. We sometimes see it left behind when a knit fails; for example, when our students attempt to knit an Rmd with Plotly figures to PDF.

    Side note: These left-behind "_files" directories can be a real PITA in a collaborative, multi-user environment, since they usually are set with write access only for the user who generated them (RStudio Server doesn't set write for the group). This is not a "bug" per se, since RStudio Server is basically doing the right thing from a security standpoint...

  5. wxli0 commented on Apr 9, 2019

    @wxli0
    Author

    The "_files" directory is not cleaned up after knit and knit does not fail (i.e. the pdf has been generated successfully). Is there any command to force Rstudio to clean it up?

  6. p-gw commented on Apr 9, 2019

    @p-gw

    This is definitely new behaviour in v1.12.

    I just looked at the recent changes in the render() function and there seem to be two changes related to #1472 and #1503:

    if (output_format$clean_supporting && !dir_exists(cache_dir)) intermediates <- c(
      intermediates, if (identical(list.files(files_dir, '^figure-.+'), files_dir_fig)) {
        files_dir
      } else knitr::opts_chunk$get('fig.path')
    )

    This is a new evaluation of the intermediate directories compard to v1.11:

    if (output_format$clean_supporting && !dir_exists(cache_dir))
      intermediates <- c(intermediates, files_dir)

    The difference between the two versions is the inclusion of files_dir in intermediates which now depends on files_dir_fig. files_dir_fig gets assigned on line 402:

    files_dir_fig <- list.files(files_dir, '^figure-.+')  # existing figure dir(s)

    Because the _files directory get created in the knit() function call later (line 650), files_dir_fig just returns character(0) instead of the actual directory. Assigning files_dir_fig after the call to knit() returns the newly created directory and cleans up the _files directory correctly for this use case.

  7. yihui commented on Apr 9, 2019

    @yihui
    Collaborator

    If I label an issue as "Bug", usually it means I have confirmed that it is a real bug, and will be fixed. If I also assign it to a milestone, it means it is important and should be fixed in the next version. Thanks for your patience!

  8. yihui commented on Apr 12, 2019

    @yihui
    Collaborator

    Should be fixed now with @cderv's PR #1566. Thanks everyone!

  9. dchiu911 commented on Apr 13, 2019

    @dchiu911

    The fix isn't passed on to rmarkdown::render_site(), hence I am still getting the directory _bookdown_files/.../figure-html/... generated

  10. cderv commented on Apr 13, 2019

    @cderv
    Collaborator

    Can you open a new issue with a reproductible example on how it worked before and how it works now ?
    I tested it with current issues and it works as I believe was expected
    I need to see how it works with rmardown website. Or maybe bookdown here I guess ?
    Also Not all rmardown format are cleanable format. A website has generally its ressources available as files and linked in the html.

  11. yihui commented on Apr 13, 2019

    @yihui
    Collaborator

    @dchiu911 Judging from the directory name _bookdown_files, it seems you were using bookdown. If that is the case, _bookdown_files won't be automatically removed. This is by design, because bookdown pages are usually not self-contained. As @cderv said, we need more information from you to know whether it is a bug or not.

  12. wxli0 commented on Apr 14, 2019

    @wxli0
    Author

    Thanks very much.
    Is updating "rmarkdown" package the only change I need to make to get rid of the _files directory?

  13. yihui commented on Apr 14, 2019

    @yihui
    Collaborator

    Yes, you can install the development version via

    remotes::install_github('rstudio/rmarkdown')
  14. dchiu911 commented on Apr 16, 2019

    @dchiu911

    @yihui if by design, not a bug, thanks.

  15. 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.

  16. 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