Setzer.Woodrow@epamail.epa.gov
2000-Dec-19 20:08 UTC
[Rd] Problem with sink() in 1.20 on Windows (PR#779)
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("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()". --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = x86 os = Win32 system = x86, Win32 status major = 1 minor = 2.0 year = 2000 month = 12 day = 15 language = R Windows 9x 4.10 (build 1998) Search Path: .GlobalEnv, Autoloads, package:base R. Woodrow Setzer, Jr. Phone: (919) 541-0128 Experimental Toxicology Division Fax: (919) 541-5394 Pharmacokinetics Branch NHEERL MD-74; US EPA; RTP, NC 27711 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel 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-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian D Ripley
2000-Dec-19 20:36 UTC
[Rd] Problem with sink() in 1.20 on Windows (PR#779)
On Tue, 19 Dec 2000 Setzer.Woodrow@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) It might be better to close the file as well as the connection when switching, but that is not what was done. To do that use sink <- function (file = NULL, append = FALSE) { if (is.null(file)) file <- 1 else if (is.character(file)) { file <- file(file, ifelse(append, "a", "w")) on.exit(close(file)) } else if (!inherits(file, "connection")) stop("`file' must be NULL, a connection or a character string") .Internal(sink(file, append)) } (One possible cause of confusion is that the connection might be closed, but not the file.) -- Brian D. Ripley, ripley@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-devel 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-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jens Oehlschlägel
2000-Dec-20 12:28 UTC
[Rd] Problem with sink() in 1.20 on Windows (PR#779)
Dear Prof. Ripley, You wrote> Yes, but what is the bug exactly?Just testing connections, I think the bug is that the help for sink says that: If `file' is a connection if will be opened if necessary. Switching to another file or connection closes the existing connection unless it is the console. and after switching to another file or connection the existing connection is not closed.> showConnections()class description mode text isopen can read can write> sink("tempfile") > sink() > showConnections()class description mode text isopen can read can write 3 "tempfile" "file" "w" "text" "opened" "no" "yes"> # now we have silently an open connection leftI tend to think that a sequence of sink(WhateverConnectionInvolved) : : sink() should leave WhateverConnectionInvolved in the same state it was before the sequence. i.e. if WhateverConnectionInvolved was non.existent it should be non.existent i.e. if WhateverConnectionInvolved was existent but not opened it should be existent but not opened i.e. if WhateverConnectionInvolved was existent and opened it should be existent and opened BTW: this may be considered as a special case of a more general thing: undefined rights to modify/access connections owned by other parts of the software. Regards Jens Oehlschlägel --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = x86 os = Win32 system = x86, Win32 status = major = 1 minor = 2.0 year = 2000 month = 12 day = 15 language = R Windows NT 4.0 (build 1381) Service Pack 6 Search Path: .GlobalEnv, package:ctest, Autoloads, package:base _______________________________________________________________________________ Alles unter einem Dach: Informationen, Fun, E-Mails. Bei WEB.DE: http://web.de Die große Welt der Kommunikation: E-Mail, Fax, SMS, WAP: http://freemail.web.de -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel 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-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Apparently Analagous Threads
- sink() does not seem to release the file
- cannot destroy connection (?) created by readLines in a tryCatch
- file descriptor leak in getSrcLines in R 2.10.0 svn 48590
- CRAN task views work only once per session (PR#9330)
- cannot destroy connection (?) created by readLines in a tryCatch