From jari.oksanen at oulu.fi  Sun Nov 15 15:58:43 2009
From: jari.oksanen at oulu.fi (Jari Oksanen)
Date: Sun, 15 Nov 2009 16:58:43 +0200
Subject: [Rd] file.rename overwrites existing target (PR#14065)
In-Reply-To: <20091115143512.B31ED2830314@mail.pubhealth.ku.dk>
Message-ID: <C725E3C3.8B9F%jari.oksanen@oulu.fi>

On 15/11/09 16:35 PM, "joehl at web.de" <joehl at web.de> wrote:

> 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.

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



[Rd] file.rename overwrites existing target (PR#14065)
Jari Oksanen