[R] Incomplete ouput with sink and split=TRUE

Duncan Murdoch murdoch at stats.uwo.ca
Wed Feb 6 14:45:04 CET 2008


On 2/5/2008 11:12 AM, jiho wrote:
> Dear List,
> 
> I am trying to get R's terminal output to a file and to the terminal  
> at the same time, so that I can walk through some tests and keep a log  
> concurrently. The function 'sink' with the option split=TRUE seems to  
> do just that. It works fine for most output but for objects of class  
> htest, the terminal output is incomplete (the lines are there but  
> empty). Here is an example session which shows the problem:

stats:::print.htest() uses writeLines to write some of its output to 
stdout(), and it looks as though sink(split=T) misses those bits.

I'll change print.htest to use cat(), but it is probably a sign of a 
bigger problem in sink(), and it's too late in the schedule to touch 
that for 2.6.2.

Duncan Murdoch

> 
>  > sink("textout.txt", type="output", split=T)
>  > b=bartlett.test(runif(10),c(1,1,1,1,2,2,2,2,2,2))
>  > class(b)
> [1] "htest"
>  > b
> 
> 
> data:  runif(10) and c(1, 1, 1, 1, 2, 2, 2, 2, 2, 2)
> 
>  > t=t.test(runif(10),c(1,1,1,1,2,2,2,2,2,2))
>  > t
> 
> 
> data:  runif(10) and c(1, 1, 1, 1, 2, 2, 2, 2, 2, 2)
> alternative hypothesis: true difference in means is not equal to 0
> 95 percent confidence interval:
>   -1.5807338 -0.7316803
> sample estimates:
> mean of x mean of y
> 0.4437929 1.6000000
> 
>  > sink()	# output in the file is complete
>  > b
> 
> 	Bartlett test of homogeneity of variances
> 
> data:  runif(10) and c(1, 1, 1, 1, 2, 2, 2, 2, 2, 2)
> Bartlett's K-squared = 0.9959, df = 1, p-value = 0.3183
> 
>  > t
> 
> 	Welch Two Sample t-test
> 
> data:  runif(10) and c(1, 1, 1, 1, 2, 2, 2, 2, 2, 2)
> t = -5.7659, df = 16.267, p-value = 2.712e-05
> alternative hypothesis: true difference in means is not equal to 0
> 95 percent confidence interval:
>   -1.5807338 -0.7316803
> sample estimates:
> mean of x mean of y
> 0.4437929 1.6000000
> 
>  >
> 
> Is this a known bug (I'm using R 2.6.1 on OS X and Linux - FC8)? Is  
> there an inherent reason why some portions of this output are not  
> redirected?
> 
> Thank you in advance for your help.
> 
> JiHO
> ---
> http://jo.irisson.free.fr/
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list