Zero byte bookdown and render files cluttering my working directory



Hi all:

I am using bookdown to build a book. Amazing tool, so thanks to Yihui.

Everytime I build the book, it is placing alot of files in my working directory that are just clutter as far as I am concerned. The offending filenames look like:

  1. bookdown12785f3e7851, or
  2. render12785f89239.rds

My guess is that these are cache files, but I am not sure. Any guidance on what these files are used for and how I can avoid seeing them in my working directory would be appreciated.

Many thanks!


These files are temporary and should be automatically cleaned up after bookdown::render_book() is done.


Thanks for the quick response. My issue is they are not automatically being cleaned up. They just accumulate.

I reinstalled bookdown, but to no avail. I know this problem did not exist initially, so I messed things up along the way.

Is there a parameter set somewhere (options() or a yml file) that requests to keep these files? I feel I might have requested temp files be kept during a debugging mission and have now forgot how to undo it.

If not, then I will do a clean reinstall.



That sounds like a bookdown bug to me. render*.rds should be cleaned up here:

bookdown* should be cleaned up here:

If you are able to figure out a fix, I'd appreciate a pull request on Github!


Pull request complete. I have created a solution that solves my problem. Basically, add recursive = TRUE to the unlink function call. You can see the problem, as it exists on my machine, reproduced using the code below. I wish I knew exactly why the recursive = TRUE argument must be passed to unlink (because it seems like it should work without that argument), but I do not. That being said, I think the fix is low-risk as other unlink calls in the render.R file already had this setting.

## mimic creation of tempFile name as is done in bookdown::render.R
tempFile = tempfile('render', '.', '.rds')
file.exists(tempFile)  ### returns FALSE, nothing written to file

## write something to file
writeLines("This is a temp file", con = tempFile)
file.exists(tempFile)  ### returns TRUE

## use unlink with default value of recursive = FALSE

## check if file exists
file.exists(tempFile)  ### returns TRUE, file still exists!

## use unlink with default value of recursive = FALSE
unlink(tempFile, recursive = TRUE)

## check if file exists
file.exists(tempFile)  ### returns FALSE, finally got rid of it

## I do not know why this option needs to be TRUE as it does not
## seem we are doing a recursive search down a directory tree.
## My only guess is it has something to to with the path specification
## as tempFile = ".\\render2b885fcas674b.rds" and I am not familiar
## with the ".\\" notation.


Commit title and # if needed: Add recursive = TRUE to unlink functions in render.R #577

Thanks for the encouragement and hints on debugging this. Much appreciated!! I am loving bookdown.


Great! Thanks! Now let's move the conversation to