-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terminating build part way through book leaves many intermediate files lying around #986
Comments
By Terminating build part part way through book, you are meaning stopping the build ? Or after an error occurs ? I'll need to try reproduce this in order to see what is happening. BTW there is a |
Generally, I mean pressing cmd + c. I suspect the problem is that the cleanup code is just run after the book is successfully built, rather than being wrapped in an |
There are a bunch of Lines 168 to 169 in 7ace59f
I'll try to reproduce and see why the cleaning is not happening |
In theory, these files should be move/cleaned since I did use |
Hmmm, weird. I double checked that you always used Another thing worth checking if it you're using relative paths and the working directory changes at some point. |
Yes in theory they should be removed. However, while investigating #920 , I stumble upon this issue with intermediary md files still present. If there is an error in the book (using Reprex: dir.create(temp_proj <- tempfile())
old <- setwd(temp_proj)
bookdown:::bookdown_skeleton('.')
#> [1] TRUE
files1 <- fs::dir_ls()
files1
#> 01-intro.Rmd 02-literature.Rmd 03-method.Rmd 04-application.Rmd
#> 05-summary.Rmd 06-references.Rmd book.bib index.Rmd
#> preamble.tex README.md style.css _bookdown.yml
#> _output.yml
content <- xfun::read_utf8("02-literature.Rmd")
content <- c(content, "```{r}", "stop('Will be an error')", '```')
xfun::write_utf8(content, "02-literature.Rmd")
yml <- yaml::read_yaml("_bookdown.yml")
yml <- c(yml, list(new_session = TRUE))
yaml::write_yaml(yml, "_bookdown.yml")
bookdown::render_book("index.Rmd", "bookdown::gitbook")
#> Error in Rscript_render(f, render_args, render_meta, add1, add2): Failed to compile 02-literature.Rmd
files2 <- fs::dir_ls()
setdiff(files2, files1)
#> [1] "01-intro.md" "01-intro.utf8.md" "02-literature.knit.md"
#> [4] "index.md" "index.utf8.md" "packages.bib"
#> [7] "_bookdown_files"
setwd(old)
unlink(temp_proj) However, the I'll double check this tomorrow, specificaly the relative path. |
I often have extra files left when the build fails because of an error, fwiw. (I make a lot of errors. lol) |
The problem is that the intermediate files are left behind by: for (f in files[rerun]) Rscript_render(f, render_args, render_meta, add1, add2) And those keep intermediate files because saveRDS(
list(output_format = output_format, ..., clean = FALSE, envir = envir),
render_args
) |
* Save render args in tempdir() * Pass clean argument to chapter render * Delete intermediate .md files Fixes #986
|
I find that I am left with many intermediate files ( I am not clicking the red 🛑 RStudio button; the render is erroring out part of the way through. |
Hmm... After you fix the error in the Rmd, bookdown should clean up the intermediate files the next time you build the book. I wasn't able to reproduce this problem the last time, but let me try again. |
Unfortunately I still can't reproduce the problem. Here I add an error chunk to d = tempfile()
dir.create(d)
owd = setwd(d)
bookdown:::bookdown_skeleton('test')
setwd('test')
cat('new_session: true\n', file = '_bookdown.yml', append = TRUE)
cat('```{r}
stop("Error")
```
', file = 'index.Rmd', append = TRUE)
bookdown::render_book() Rendering cat(list.files(), sep = '\n')
Then I remove the error chunk and re-render: xfun::process_file('index.Rmd', function(x) head(x, -3))
bookdown::render_book()
cat(list.files(), sep = '\n')
The intermediate Same thing when building the book with the RStudio IDE. So I still need a reproducible example... |
Let me see if I can put one together soon; I think the problem may be related to how caching is working when some chunks depend on something that has errored. |
To help with this, @apreshill suggested to look into https://github.com/rstudio-education/stat545 where this problem was also encountered while collaborating on the book. |
Well, I spent some time today trying to generate this type of problem in a small bookdown repo, and I was not successful. 😔 The small bookdown would always build successfully after I removed the error (even playing with caching and chunk dependencies). Unfortunately I can't offer a small reproducible example of the problems I experienced for now, but I will update you all in the future if/when I come upon it again! |
Thank you anyway! When we resolve the rmarkdown issue rstudio/rmarkdown#2086, this bookdown issue should also be resolved. |
@yihui I have took some time to look into this issue. A reminder: there was a weird interaction between rlang and bookdown in #920 Based on your examples, and a more complex project like mentioned in #986 (comment), I went further. But there will still be the intermediates .md files as the merged has not happened yet (in knit and merge approach) d = tempfile()
dir.create(d)
owd = setwd(d)
bookdown:::bookdown_skeleton('test')
setwd('test')
cat('new_session: true\n', file = '_bookdown.yml', append = TRUE)
cat('```{r}
stop("Error")
```
', file = '05-summary.Rmd', append = TRUE)
bookdown::render_book('.')
xfun::raw_string(list.files())
It seems currently those xfun::process_file('05-summary.Rmd', function(x) head(x, -3))
bookdown::render_book(".") > xfun::raw_string(list.files())
_book
_bookdown.yml
_bookdown_files
_output.yml
01-intro.Rmd
02-literature.Rmd
03-method.Rmd
04-application.Rmd
05-summary.Rmd
06-references.Rmd
book.bib
index.Rmd
packages.bib
preamble.tex
README.md
style.css
test.rds
> xfun::raw_string(list.files("_book"))
01-intro.md <-- moved
01-intro_files
02-literature.md <-- moved
03-method.md <-- moved
04-application.md <-- moved
05-summary.md <-- moved
06-references.md <-- moved
applications.html
final-words.html
index.html
index.md
intro.html
libs
literature.html
methods.html
reference-keys.txt
references.html
search_index.json
style.css I believe on suggestion in #1079 is to remove the Why are those .md files moved to output dir by the way ? I am not sure to follow the purpose. If an error occurs during
I believe most of the issue here is to be sure the correct |
e.g. all of the
.md
files of the chapters built so far, and a number ofrender*.rds
The text was updated successfully, but these errors were encountered: