[Rd] file.rename overwrites existing target (PR#14065)
Jari Oksanen
jari.oksanen at oulu.fi
Sun Nov 15 15:58:43 CET 2009
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
More information about the R-devel
mailing list