From phgrosjean at sciviews.org  Sat Dec 29 12:15:26 2007
From: phgrosjean at sciviews.org (phgrosjean at sciviews.org)
Date: Sat, 29 Dec 2007 12:15:26 +0100 (CET)
Subject: [Rd] capture.output(), truncated last output without \n (PR#10534)
Message-ID: <20071229111526.1015E2834619@mail.pubhealth.ku.dk>

Full_Name: Philippe Grosjean
Version: 2.6.1
OS: MacOS X; Windows XP
Submission from: (NULL) (81.243.237.235)


Last output from capture.output() is truncated if it does not end with a
carriage return:

> capture.output(cat("text\n"))  # Fine
[1] "text"
> capture.output(cat("text"))    # Missing output!
character(0)
> capture.output({cat("text");1+1})  # Only last output is affected
[1] "text[1] 2"

Proposed patch: add a carriage return before exiting capture.output():

capture.output <-
function (..., file = NULL, append = FALSE) {

    
[...]

        for (item in tmp) if (item$visible) 
            print(item$value)
    }
    cat("\n")  ### ADD THIS!
    rval
}

This changes the behavior of capture.output() a little bit, since it adds "" at
the end of regular outputs, but it solves the problem and it allows to detect if
last output line was ended by \n, or not.

Regards,

Philippe Grosjean
               _                           
platform       i386-apple-darwin8.10.1     
arch           i386                        
os             darwin8.10.1                
system         i386, darwin8.10.1          
status                                     
major          2                           
minor          6.1                         
year           2007                        
month          11                          
day            26                          
svn rev        43537                       
language       R



[Rd] capture.output(), truncated last output without \n (PR#10534)
phgrosjean at sciviews.org