Permalink
Browse files

Do not create corrupt RDS file if the object to serialize does not exist

(saveRDS, PR#17358).


git-svn-id: https://svn.r-project.org/R/trunk@74238 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information...
kalibera
kalibera committed Feb 8, 2018
1 parent b3ccff1 commit 924582943706100e88a11d6bb0585d25779c91f5
Showing with 2 additions and 1 deletion.
  1. +2 −1 src/library/base/R/serialize.R
@@ -1,7 +1,7 @@
# File src/library/base/R/serialize.R
# Part of the R package, https://www.R-project.org
#
# Copyright (C) 1995-2017 The R Core Team
# Copyright (C) 1995-2018 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@ saveRDS <-
{
if(is.character(file)) {
if(file == "") stop("'file' must be non-empty string")
object <- object # do not create corrupt file if object does not exist
mode <- if(ascii %in% FALSE) "wb" else "w"
con <- if (is.logical(compress))
if(compress) gzfile(file, mode) else file(file, mode)

0 comments on commit 9245829

Please sign in to comment.