You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rmarkdown creates _files directory not cleared #1553
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!
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...
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?
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
} elseknitr::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:
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.
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!
Reacted by Christophe Dervieux, Philipp Gewessler, Andrés Castro Socolich, Wanxin Li and John S. Erickson, Ph.D.
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.
@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.
Activity
wxli0 commentedon Apr 8, 2019
Is there any update on this issue?
olyerickson commentedon Apr 9, 2019
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...
wxli0 commentedon Apr 9, 2019
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?
p-gw commentedon Apr 9, 2019
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:This is a new evaluation of the intermediate directories compard to v1.11:
The difference between the two versions is the inclusion of
files_dirinintermediateswhich now depends onfiles_dir_fig.files_dir_figgets assigned on line 402:Because the
_filesdirectory get created in theknit()function call later (line 650),files_dir_figjust returnscharacter(0)instead of the actual directory. Assigningfiles_dir_figafter the call toknit()returns the newly created directory and cleans up the_filesdirectory correctly for this use case.yihui commentedon Apr 9, 2019
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!
yihui commentedon Apr 12, 2019
Should be fixed now with @cderv's PR #1566. Thanks everyone!
dchiu911 commentedon Apr 13, 2019
The fix isn't passed on to
rmarkdown::render_site(), hence I am still getting the directory_bookdown_files/.../figure-html/...generatedcderv commentedon Apr 13, 2019
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.
yihui commentedon Apr 13, 2019
@dchiu911 Judging from the directory name
_bookdown_files, it seems you were using bookdown. If that is the case,_bookdown_fileswon'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.wxli0 commentedon Apr 14, 2019
Thanks very much.
Is updating "rmarkdown" package the only change I need to make to get rid of the _files directory?
yihui commentedon Apr 14, 2019
Yes, you can install the development version via
dchiu911 commentedon Apr 16, 2019
@yihui if by design, not a bug, thanks.
github-actions commentedon Nov 3, 2020
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.