joehl at web.de
2009-Nov-15 14:35 UTC
[Rd] file.rename overwrites existing target (PR#14065)
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> cat("a\n", file="a.txt") > cat("b\n", file="b.txt") > file.rename("a.txt","b.txt")[1] TRUE> readLines("b.txt")[1] "a"> version_ 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:> 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
Gabor Grothendieck
2009-Nov-15 15:09 UTC
[Rd] file.rename overwrites existing target (PR#14065)
On Sun, Nov 15, 2009 at 9:58 AM, Jari Oksanen <jari.oksanen at oulu.fi> wrote:> 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 theOn 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.
Jens Oehlschlägel
2009-Nov-15 23:15 UTC
[Rd] file.rename overwrites existing target (PR#14065)
Thanks, An overwrite flag would be great. Would make it cristal clear what the expected behaviour is. Agree that unix behaviour should in case of doubt have priority - in this case: documentation would help windows users. Regards Jens
Maybe Matching Threads
- basename returns "." not in filename (PR#13958)
- please help with estimation of true correlations andreliabilities
- How to grow an R object from C (.Call Interface)
- problems with assigning a class to an environment
- How to return a big treelike list from .Call Interface (protect stack overflow)