[R] sink() does not seem to release the file

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jan 2 12:33:10 CET 2001


To add to that, this behaviour has been changed in the R-patched version
(and hence for 1.2.1): from NEWS/BUG FIXES

    o   Explicitly close files opened by sink() for OSes (such as
        Windows) that benefit from it.

In other words, sink() will close the connection for you.


On 2 Jan 2001, Peter Dalgaard BSA wrote:

> "BXC (Bendix Carstensen)" <bxc at novonordisk.com> writes:
> 
> > I run Win2000, and when I try to write to a file and later use it
> > it seems that R 1.02.0 has a firm grip on it:
> 
> [Proof deleted]
> 
> This was on the R-devel list 2 weeks ago:
> 
> On Tue, 19 Dec 2000, Prof Brian D Ripley wrote:
> 
> > On Tue, 19 Dec 2000 Setzer.Woodrow at epamail.epa.gov wrote:
> > 
> > > When I use sink(filename) to save the results of the run, the file
> > > does not seem to be closed or released back to the OS after I issue
> > > the "sink()" command.  Here is a baby example:
> > 
> > sink works on connections, not files, as from 1.2.0.
> > 
> > > sink("test.txt")
> > > tdta <- data.frame(x = x <- 0:10,y = 2 * x + rnorm(11))
> > > 
> > > print(summary(lm(y ~ x, data=tdta)))
> > > sink()
> > > 
> > > At this point (even after refreshing the Explorer window) the filesize of
> > > "test.txt" is listed as 0 bytes, and as long as Rgui is running, I
> > > cannot delete the file.  Emacs cannot read the file (but Notepad can).  This happens both in the gui
> > > and when the commands are in a file run via "source()".
> > 
> > Yes, but what is the bug exactly?  The connection is still open so you can
> > switch output back to it.  If you want different behaviour, you can open a
> > connection and close it yourself.  As in
> > 
> > zz <- file("test.txt", "w")
> > sink(zz)
> > tdta <- data.frame(x = x <- 0:10,y = 2 * x + rnorm(11))
> > print(summary(lm(y ~ x, data=tdta)))
> > sink()
> > close(zz)
> 
> -- 
>    O__  ---- Peter Dalgaard             Blegdamsvej 3  
>   c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
>  (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list