[R] using the sink() function in a for-look

Rolf Turner r.turner at auckland.ac.nz
Thu May 1 06:59:29 CEST 2008


On 1/05/2008, at 4:40 PM, Johannes Hüsing wrote:

> Tony Dell <anthony.dell at jcu.edu.au> [Thu, May 01, 2008 at  
> 04:32:23AM CEST]:
>> hi all,
>>
>> i wanted to use the sink function to sequentially output regression
>> summaries within a for-loop. i must have something wrong somewhere  
>> (or be
>> using the sink function incorrectly), but can anyone help?
>>
>> the code I am using is:
>>
>
> Please use code and data which is reproducible for us. As we don't  
> have
> access to your data, we'd have to construct some of our own.
>
> This code, however, has the same effect:
>
> for (i in 1:100) {
>     sink("./sometext.txt", append=TRUE)
>     summary(rnorm(80))
>     sink()}
>
>
> When you do the following:
>
> for (i in 1:100) {
>     summary(rnorm(80))}
>
> what output do you get?

	He'd get nothing at all.

	Did you ***try*** your code?

> And all this output

	``All this output''!  Consisting of the empty set !!!

> is redirected to your file by sink(), so it works
> as expected.

	That all depends on what you expect, I guess.  Most people
	would expect to get some output.  As Tony expected.

		cheers,

			Rolf Turner

######################################################################
Attention: 
This e-mail message is privileged and confidential. If you are not the 
intended recipient please delete the message and notify the sender. 
Any views or opinions presented are solely those of the author.

This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com
######################################################################



More information about the R-help mailing list