[R] Antwort: Antwort: Re: Re: Antwort: Re: Re: sink(): Cannot open file

G.Maubach at weinwolf.de G.Maubach at weinwolf.de
Thu May 12 11:10:08 CEST 2016


Hi Martin,

many thanks for following-up on my question.

I did it again:

## capture all the output to a file.
zz <- file("C:/Temp/all.Rout", open = "wt")
sink(zz)
sink(zz, type = "message")
try(log("a"))
## back to the console
sink(type = "message")
sink()
close(zz)

This works.

I tried several other combinations of the commands, e.g.

## capture all the output to a file.
zz <- file("C:/Temp/all.Rout", open = "wt")
sink(zz)
sink(zz, type = "message")
try(log("a"))
close(zz)

Does not work.

As far as I have understood right now, I have to loosen the connection of 
the streams with sink(zz, type = "message") and sink() before I can close 
the file connection itself.

If I did it like in the last example the connection to the file is lost 
and then the connection to the streams of sink() can not be recovered. 
This will last until the R session is closed and opened again.

To me it looks like I need to learn more about the operation of R under 
the hood.

Kind regards

Georg




Von:    Martin Maechler <maechler at stat.math.ethz.ch>
An:     <G.Maubach at weinwolf.de>, 
Kopie:  Sarah Goslee <sarah.goslee at gmail.com>, <r-help at r-project.org>
Datum:  12.05.2016 10:40
Betreff:        [R] Antwort: Re: Re:  Antwort: Re: Re: sink(): Cannot open 
file




> Hi Sarah,
> yes, I followed your suggestion.

I doubt that you followed it correctly. Sarah's advise is
usually really very sound -- and your code below is *not* :

> If I do exactly what is in the example of the documentation:

> sink("C:/Temp/sink-examp.txt")
> i <- 1:10
> outer(i, i, "*")
> sink()
> unlink("C:/Temp/sink-examp.txt")

> it does not write anything, i. e. no file is created in "C:/Temp/". The 
> script is executed without an error or warning message.

Well, did you ever lookup what unlink() does ?
I save you the time : it does *REMOVE* a file.

So no wonder that you don't see any result after executing the
above R code block..

Martin



More information about the R-help mailing list