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

From: François Pinard <>
Date: Thu 23 Feb 2006 - 23:14:54 GMT

[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
> 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:

R --slave --vanilla <<EOF


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

______________________________________________ mailing list
Received on Fri Feb 24 10:24:55 2006

This archive was generated by hypermail 2.1.8 : Fri 24 Feb 2006 - 01:16:09 GMT