BXC (Bendix Carstensen)
2001-Jan-02 10:57 UTC
[R] sink() does not seem to release the file
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:> 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> sink("foo") > cat("some text") > sink() > shell("type foo")some text> shell("dir f*")Volume in drive N is Local Disk Volume Serial Number is 1C5E-3A70 Directory of N:\Bendix\Steno\JaSv\iddm 02-01-2001 11:33 9 foo 1 File(s) 9 bytes 0 Dir(s) 172.857.344.000 bytes free> shell("del foo")N:\Bendix\Steno\JaSv\iddm\foo The process cannot access the file because it is being used by another process. However, when I fire up my old R 1.01.1 (which is not installed under Win2000, but merely a verbatim copy from my old NT4 machine), I get:> version_ platform Windows arch x86 os Win32 system x86, Win32 status major 1 minor 1.1 year 2000 month August day 15 language R> sink("oof") > cat("any text") > sink() > shell("type oof")any text> shell("dir oo*")Volume in drive N is Local Disk Volume Serial Number is 1C5E-3A70 Directory of N:\Bendix\Steno\JaSv\iddm 02-01-2001 11:37 8 oof 1 File(s) 8 bytes 0 Dir(s) 172.857.339.904 bytes free> shell("del oof") > shell("dir oo*")Volume in drive N is Local Disk Volume Serial Number is 1C5E-3A70 Directory of N:\Bendix\Steno\JaSv\iddm File Not Found Warning message: cmd execution failed with error code 1 in: shell("dir oo*")>Is this a new bug or a new facility?? I have a vague recollection that a similar problem was also present in an older version of R, too. The workaround in R 1.2 is to:> shell("copy foo oof")and then use oof for the relevant purpose. The background for this is that I use R to write a small SAS-program that writes a SAS-dataset in a read.table format, that I then read into R. But when strted from withn R, SAS complains that the program file just sink()ed by R is in use (apparently by R). Any one interested can get the rather clumsy sas.get.R and the corresponding %out SAS-macro from me on request. Requires that SAS is on your macine as well. No bells and whistles at all. Bendix Carstensen ---------------------- Bendix Carstensen Senior Statistician Steno Diabetes Centre Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 28 25 87 38 fax: +45 44 43 73 13 bxc at novo.dk www.biostat.ku.dk/~bxc ---------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._