-
-
Couldn't load subscription status.
- Fork 52
Description
Issue
When writing an RDS file, it might fail half way through, resulting in an incomplete, corrupt file. Similarly, if one process attempts to read a file that is currently being written by another process, the read might occur on an incomplete file.
Suggestion
Always write RDS file atomically. This can be achieved by writing to *.rds.tmp and then rename the file to *.rds after saveRDS() completes. This way the target *.rds is guaranteed to be complete.
By writing to *.rds.tmp instead of tempfile() guarantees that we write to the same drive, avoiding cross-drive moves and copies.
Patch
See PR #316 for a patch. I updated writeRDS() to write atomically and I've added wait = 300, which can optionally be set to wait = 0. The latter is used to replace two remaining saveRDS() uses.