[R] Writing output to a file in a loop

Wojtek Slusarski slusek at o2.pl
Thu Feb 10 13:50:37 CET 2005


Roger Bivand wrote:

> First, you should enclose the functions that output results in the loop in 
> print(), so that they do print, in loops this has to be done and is a FAQ 
> (often met with lattice graphics)

I am sorry for that, that I didn't find that. Now it works great. If 
anyone needs that, that's what I have inside the loop:

sink("zz.txt", append = TRUE)

	print(out <- summary(fit))
	print(out <- logLik(fit))

sink()

>>The most wondering thing for me is that, plots are stored in the ps 
>>file, but only the ones from last iteration. In manuals there is:
>>
>>append: logical; currently *disregarded*; just there for
>>           compatibility reasons.
>>
>>What does *disregarded* actually mean and when I will be able to add a 
>>title before each set of plots, because now the option title is not 
>>adding anything to file.
>>
> 
> Well disregarded here seems to mean exactly that. Why not open the 
> postscript device before the loop starts, with onefile = TRUE, write to it 
> in the loop, then dev.off() after the loop? You are getting the last 
> graphic because that is what you are telling it to do, the others are 
> being overwritten, because you are opening and closing the same file 
> inside the loop, and append doesn't exist. 

Well, I don't know how to change the properties main, xlab and ylab in 
the GARCH object for plots, when I do plot(fit), so I made for each 
model separate file containing name of the model and date. Those plots 
are just for me, to have a look if the residuals from the model are OK. 
I am not going to print them.

Once again, thanks a lot.

Best regards,
Wojtek Slusarski




More information about the R-help mailing list