Skip to content

Help to write to a file

6 messages · Sarah Goslee, michael.weylandt at gmail.com (R. Michael Weylandt, Duncan Murdoch +2 more

#
Hi,

Inside a loop, you must explicitly wrap your summary() command and anything
else from which you expect output in a print() command.

Sarah

2011/10/11 Sergio Ren? Araujo Enciso <araujo.enciso at gmail.com>:

  
    
Untested, does adding a print() around summary() get it done?

Michael
On Oct 11, 2011, at 1:03 PM, Sergio Ren? Araujo Enciso <araujo.enciso at gmail.com> wrote:

            
#
On 11/10/2011 1:03 PM, Sergio Ren? Araujo Enciso wrote:
You aren't printing anything.  In a loop, you need to call print() 
explicitly; only the last value of an expression auto-prints.

Duncan Murdoch
#
On Oct 11, 2011, at 1:03 PM, Sergio Ren? Araujo Enciso wrote:

            
You may need to print() that summary-object inside the for-function.

 > summary(a)
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
    1.00    1.75    2.50    2.50    3.25    4.00
 > sink("test.txt")
 > for(i in 1) summary(a)
 > sink()    # No test.txt file created
 > sink("test2.txt")
 > for(i in 1) print( summary(a) )
 > sink() # The expected file created

This relates to the FAQ about similar puzzling behavior with plotting  
lattice , grid or ggplot objects.
David Winsemius, MD
West Hartford, CT