Skip to content

file.rename overwrites existing target (PR#14065)

3 messages · Jens Oehlschlägel, Jari Oksanen, Gabor Grothendieck

#
Full_Name: Jens Oehlschl?gel
Version: 2.10.0
OS: Windows XP Professional
Submission from: (NULL) (85.181.158.112)


file.rename() will successfully rename file a to b - even if b exists already. 
Though the documentation does not state what file.rename() will do in this
case,
I guess the expected behaviour is to fail and return FALSE.

Kind regards

Jens Oehlschl?gel
[1] TRUE
[1] "a"
_                            
platform       i386-pc-mingw32              
arch           i386                         
os             mingw32                      
system         i386, mingw32                
status                                      
major          2                            
minor          10.0                         
year           2009                         
month          10                           
day            26                           
svn rev        50208                        
language       R                            
version.string R version 2.10.0 (2009-10-26)
#
On 15/11/09 16:35 PM, "joehl at web.de" <joehl at web.de> wrote:

            
The *expected* behaviour is to overwrite the old file. Your expectation
seems to be different, but overwriting or deleting the old file has been the
behaviour for ever (= since 1970s). This is how MacOS defines the behaviour
of the system command 'rename':

RENAME(2)                   BSD System Calls Manual

NAME
     rename -- change the name of a file
...
DESCRIPTION
     The rename() system call causes the link named old to be renamed as
new.
     If new exists, it is first removed.

The behaviour is the same in all posixy systems. Sebsinble systems like R
follow the documented standard behaviour.

Why would you expect that 'file.rename' fails if the 'new' file exists?

The unix command 'mv' (move) that does the 'rename' has a switch to overturn
the standard 'rename' system call, and prompt for the removal of the 'new'
file. However, this switch is usually not the default in unixy systems,
unless defined so in the shell start up script of the user.

Cheers, Jari Oksanen
#
On Sun, Nov 15, 2009 at 9:58 AM, Jari Oksanen <jari.oksanen at oulu.fi> wrote:
On UNIX the expected behavior would be to overwrite but on Windows the
rename command does not overwrite silently but fails so I think his
expectation is in line with how Windows works at the command line
level.  It might be worthwhile to have an overwrite= argument on
file.rename to control this.  If it defaulted to TRUE then the
expectation would be clear regardless of platform.