Re: [Rd] file.rename overwrites existing target (PR#14065)

From: Jari Oksanen <>
Date: Sun, 15 Nov 2009 16:58:43 +0200

On 15/11/09 16:35 PM, "" <> wrote:

> Full_Name: Jens Oehlschlägel
> Version: 2.10.0
> OS: Windows XP Professional
> Submission from: (NULL) (
> 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

     rename -- change the name of a file
     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 mailing list Received on Sun 15 Nov 2009 - 15:06:23 GMT

This archive was generated by hypermail 2.2.0 : Sun 15 Nov 2009 - 17:10:25 GMT