Skip to content

save() should not overwrite a file if an error occurs (PR#12583)

2 messages · Tim Hesterberg, Henrik Bengtsson

#
If save() fails because an object is not found,
it should not overwrite an existing file.
[1]  1  2  3  4  5  6  7  8  9
Error in save(a, file = "a.rda") : object 'a' not found
Error in load("a.rda") : error reading from connection

I've been saving copies of huge objects into
files like a.rda, then removing the objects.
If I then happen to save again, I don't want to lose
my data.


--please do not edit the information below--

Version:
 platform = i486-pc-linux-gnu
 arch = i486
 os = linux-gnu
 system = i486, linux-gnu
 status =
 major = 2
 minor = 7.1
 year = 2008
 month = 06
 day = 23
 svn rev = 45970
 language = R
 version.string = R version 2.7.1 (2008-06-23)

Locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

Search Path:
 .GlobalEnv, package:Rfixes, package:Rcode, package:aggregate,
package:stats, package:graphics, package:grDevices, package:utils,
package:datasets, package:showStructure, package:splus2R, package:methods,
Autoloads, package:base
#
I don't know what save() "should" do - your use case is quite special
- but I agree it would be better if save() tests for the existence of
all object(s) to be saved before opening the connection (and thereby
overwrite the existing file).  A workaround for you is to do:

dummy <- a;
save(a, file="a.rda");

This should give an error before save() is called.

FYI, saveObject() of R.utils does protect you this way too, e.g.
[1] 1 2 3 4 5 6 7 8 9
Error in saveObject(a, file = "a.rda") : object "a" not found
[1] 1 2 3 4 5 6 7 8 9

/Henrik
On Fri, Aug 22, 2008 at 3:45 PM, <timhesterberg at gmail.com> wrote: