saveRDS() overwrites file when object is not found

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

saveRDS() overwrites file when object is not found

Kenny Bell-2
I ran into this behaviour when accidentally running a line of code that I
shouldn't have.

When saving over an rds with an object that's not found, I would have
expected saveRDS to not touch the file.

saveRDS(iris, "test.rds")
file.size("test.rds")
#> [1] 1080
saveRDS(no_object_here, "test.rds")
#> Error in saveRDS(no_object_here, "test.rds"): object 'no_object_here'
not found
file.size("test.rds")
#> [1] 20
file.remove("test.rds")

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: saveRDS() overwrites file when object is not found

Tomas Kalibera
Thanks, this has been already reported as bug 17358. Addressed in
R-devel 74238. R may still create a corrupt file, though, in other
circumstances (e.g. if it runs out of memory or is interrupted during
serialization, etc).

Tomas

On 02/07/2018 04:14 PM, Kenny Bell wrote:

> I ran into this behaviour when accidentally running a line of code that I
> shouldn't have.
>
> When saving over an rds with an object that's not found, I would have
> expected saveRDS to not touch the file.
>
> saveRDS(iris, "test.rds")
> file.size("test.rds")
> #> [1] 1080
> saveRDS(no_object_here, "test.rds")
> #> Error in saveRDS(no_object_here, "test.rds"): object 'no_object_here'
> not found
> file.size("test.rds")
> #> [1] 20
> file.remove("test.rds")
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel