[Rd] Spurious output white line in R script (PR#8631)

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Feb 23 17:53:19 CET 2006


On Thu, 23 Feb 2006, Thomas Lumley wrote:

> On Thu, 23 Feb 2006, Prof Brian Ripley wrote:
>
>> On Wed, 22 Feb 2006, François Pinard wrote:
> [...]
>>> 
>>> So, I was not expecting R, running with that option activated, to
>>> "volunteer" white lines. :-)
>> 
>> But Simon said `with the documentation'.  Not doing what you expected is
>> not a bug.  Can you please point us to documentation which says that
>> end-of-file produces no output?
>> 
>> This does appear to be deliberate behaviour from
>> 
>> void end_Rmainloop(void)
>> {
>>    Rprintf("\n");
>>    /* run the .Last function. If it gives an error, will drop back to main
>>       loop. */
>>    R_CleanUp(SA_DEFAULT, 0, 1);
>> }
>> 
>> and I think it is necessary, as R might well have a partial line of output 
>> queued up for the console.  So this is probably `as quietly as possible'.
>
> (While agreeing entirely on the "bug" issue), couldn't we have fflush() 
> instead of sending a newline?

Well, we might not be outputting to a file ... (I did say console), and 
.Last() might well produce output so we need to leave the console in a 
suitable state.  I do think we need a \n unless we can be sure that we are 
currently at the left margin of the console (and I am not sure we can be 
unless we assume all output went through R[E]printf, and even in that 
case we do not currently collect the information).

Consider the script

gannet% cat foo
#!/bin/sh
R --slave --vanilla <<EOF

.Last <- function() cat("goodbye\n")
cat("Hello")
EOF

which produces

gannet% foo.R
Hello
goodbye
gannet%

We do not want

gannet% foo.R
Hellogoodbye
gannet%

or at least, I do not want that.


Beyond that, there must be hundreds or more reference results of test runs 
against which comparisons are made, and this might well affect a lot of 
testing code, although perhaps we could conditionalize on --slave.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-devel mailing list