From ripley at stats.ox.ac.uk  Sun Oct 18 00:03:23 2009
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sat, 17 Oct 2009 23:03:23 +0100 (BST)
Subject: [Rd] (PR#14012)
In-Reply-To: <20091017210301.GC1411@orange.local>
References: <20091016130010.3717A282EFF1@mail.pubhealth.ku.dk>
	<20091017210301.GC1411@orange.local>
Message-ID: <alpine.LFD.2.00.0910172225300.13083@gannet.stats.ox.ac.uk>

On Sat, 17 Oct 2009, Seth Falcon wrote:

> * On 2009-10-16 at 15:00 +0200 sje30 at damtp.cam.ac.uk wrote:
>> I think Rscript has a problem running files that have mac encodings
>> for newline (^M rather than ^J on linux).

I think those are Mac conventions for end-of-line, not for newline. 
Even in MacRoman encoding, Ctrl-M is carriage return and Ctrl-J is 
newline aka linefeed..

>> If I source the file within R, it works okay:
>
>>> source('j.R')
>> [1] "MEA_data/sernagor_new/CRX_P7_1.txt"
>>
>> But if I run the file using Rscript on a linux box I get a strange
>> error message:
>>
>> $ Rscript --vanilla j.R
>> "
>> Execution halted
>
> I think you are right that Rscript is unhappy to handle files with CR
> line terminators.

More accurately, R's parser is: this applies to R CMD BATCH and R 
itself with redirection.  The point is that the documentation says
that R commands have to be separated by newline or semicolon and CR is 
neither.  (See, e.g. R-intro section 1.8.)

It is also documented that text-mode connections (which source() uses) 
map CR and CRLF to newline, so source() can accept CR-delimited files.

And the error message looks strange because it has CRs but not NLs in 
it (since the input did) and presumably the terminal used replaces not 
superposes characters.

What actually is claimed to be the bug here?  There is no subject 
line, and no clear statement.  Is that Rscript gives an error, that 
source() works or that the error message comes out mangled on a 
particular terminal?


> But IIUC, the purpose of Rscript is to enable R script execution on 
> unix-like systems like:
>
>   #!/path/to/Rscript --vanilla
>   print(1:10)
>
> So then I'm not sure how useful it is for Rscript to handle such
> files.  Why not convert to a more common and portable line termination
> for your R script files?
>
>
> + seth
>
> -- 
> Seth Falcon | @sfalcon | http://userprimary.net/user
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

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



[Rd] (PR#14012)
Prof Brian Ripley