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

From: François Pinard <pinard_at_iro.umontreal.ca>
Date: Wed 22 Feb 2006 - 23:10:22 GMT

[Simon Urbanek]

>I don't see the bug here ... you may want to explain how this behavior
>conflicts with the documentation.

Oh, sorry. I merely surmised that R developers were aware of the meaning of "--slave" option. 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. :-)

>If you don't want it, tell R to explicitly terminate in your script,
>e.g. with quit("no",0) - then there will be no new line.

Thanks for this work-around, which solves the problem of the spurious white line at end of script. I did not need arguments on the q() call, first because the "no" is already implied through "default" from the "--vanilla" option and second because 0 is also the default exit status.

Yet, it sounds reasonable to suggest (or hope) that R interprets an end-of-file as meaning that R should cleanly quit. I naively thought that it does this already, from the fact that interactively at least, R seems to behave on a Ctrl-D as if q() has been called.

This is either right or wrong using an end-of-file instead of calling q(). If it is right to use end-of-file instead of an explicit q() call, I'm reporting a bug. If it is wrong to use end-of-file instead of an explicit q() call, I'm rather making a suggestion. :-)

If you consider that the user is definitely wrong by not calling q() explicitly, and that various unexpected things may then happen, R would be friendlier if it produced a diagnostic, hitting an end-of-file while expecting a statement. Interactively, it could even go further, and nicely remind the user, at the time the user types Ctrl-D, that calling q() is the only proper way for cleanly terminating an R session.

>On Feb 22, 2006, at 1:41 PM, pinard@progiciels-bpi.ca wrote:

>>I noticed that R scripts produce a spurious white line after output.
>>For example, the following shell script,

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

>>cat("Hello\n")

>>EOF

>>when made executable under the name ``hello`` along the search
>>path, behaves
>>like this:

>>$ hello | od -bc
>>0000000 110 145 154 154 157 012 012
>> H e l l o \n \n
>>0000007

>>The second newline is not wanted, and I would like if R was not
>>producing it.

>Cheers,
>Simon

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

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu Feb 23 10:13:14 2006

This archive was generated by hypermail 2.1.8 : Thu 23 Feb 2006 - 07:15:56 GMT