[Rd] Spurious output white line in R script (PR#8631)
François Pinard
pinard at iro.umontreal.ca
Fri Feb 24 00:14:54 CET 2006
[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
More information about the R-devel
mailing list