From pinard at iro.umontreal.ca  Fri Feb 24 00:14:54 2006
From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard)
Date: Thu, 23 Feb 2006 18:14:54 -0500
Subject: [Rd] Spurious output white line in R script (PR#8631)
In-Reply-To: <Pine.LNX.4.64.0602230552410.24547@gannet.stats.ox.ac.uk>
References: <20060222184113.A6F1B3F70C@slim.kubism.ku.dk>
	<20A69DDC-E571-4DD1-9047-0073F47FA7CF@r-project.org>
	<20060222231022.GA24313@phenix.sram.qc.ca>
	<Pine.LNX.4.64.0602230552410.24547@gannet.stats.ox.ac.uk>
Message-ID: <20060223231454.GA29213@alcyon.progiciels-bpi.ca>

[Brian Ripley]
>[Fran?ois Pinard]

>>Within the output resulting of command "man R", one reads:

>>       --slave
>>              Make R run as quietly as possible

>>So, I was not expecting R, running with that option activated, to
>>"volunteer" white lines. :-)

>Can you please point us to documentation which says that end-of-file 
>produces no output?

I just did.  However, you state that "as quietly as possible" should not 
be interpreted as "no output".  Our interpretations differ.

>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'.

I do not doubt that it is deliberate, and I suspected as much even 
before submitting my initial report on this topic, as I do the same in 
some interactive programs I wrote, so the shell prompt shows at the 
left.  However, I'm careful at not doing it outside human-interactive 
contexts.

It is likely unusual that R users starts an R session with "--slave",
when that session is really meant to be human-interactive.  Whatever the 
documentation says or does not say, the spurious '\n' kludge has no good 
reason to apply with "--slave".  Let's both be trying to have 
a reasonable and intelligent conversation here, keeping in mind that the 
documentation is not necessarily perfect either, and not the last word 
of everything.

The argument that it is necessary to write a '\n' because a partial line 
of output may be queued up for the console, does not fully hold.  Proof 
is, following Simon Urbanek's suggestion, that the following valid 
R script:


#!/bin/sh
R --slave --vanilla <<EOF

cat("Hello")
q()

EOF


produces such a partial line.  I see no problem there: when using 
"--slave", a script writer should feel in good control of the produced 
output, and s/he will recognise a missing newline as a bug in the 
script, not as a bug in R.

If the newline is a way to flush out the output buffer before quitting, 
the suggestion made by others to use `fflush()', or anything similar, is 
wise.  Adding a newline when "--slave" has not been selected, and 
whenever the output is connected to a tty, is also wise, regardless if 
termination is effected through q() or through hitting end-of-file.

Not adding a newline in other circumstances is debatable, but wise.

It is also reasonable (whether documented or not) expecting that q() and 
hitting end-of-file act similarly.  Some developers (or maybe none) 
might even recognise they attempted it already.  Let me suggest that 
this similarity is aimed, and even documented.

-- 
Fran?ois Pinard   http://pinard.progiciels-bpi.ca



[Rd] Spurious output white line in R script (PR#8631)
=?iso-8859-1?Q?Fran=E7ois?= Pinard