Re: [Rd] clients and carriage returns

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Wed, 20 Jun 2007 18:26:49 +0100 (BST)

I think the question is how are you accessing the parser? The only public interface is R_ParseVector, and that works like parse(text=):

> parse(text="abc\ndef")

expression(abc, def)
attr(,"srcfile")
<text>
> parse(text="abc\r\ndef")

Error in parse(text = "abc\r\ndef") :
" syntax error, unexpected $undefined, expecting '\n' or ';' in "abc

This does not happen when reading from files, as the connection machinery converts line endings (or fgets does). So I think the problem may be in how you (or PostgreSQL) are getting text from files.

The rules of R syntax are quite simple, e.g.

   Newlines have a function which is a combination of token separator and    expression terminator. If an expression can terminate at the end of    the line the parser will assume it does so, otherwise the newline is    treated as whitespace. Semicolons (@samp{;}) may be used to separate    elementary expressions on the same line.

(from R-lang.texi).

On Wed, 20 Jun 2007, Joe Conway wrote:

> I've recently ported PL/R (R embedded in Postgres as a procedural
> language) to work on Win32 -- thank you to all involved for making the
> embedded interface common between *nix and Win32!
>
> This of course means users are now creating PL/R functions using Win32
> based editors, which are using \r\n for EOL. I had not realized this
> before, but R throws a parse error when it sees \r, even on a Win32 OS.
> Near as I can tell browsing R source, this is true on all operating
> systems -- e.g. gram.y seems to look only for \n, and in
> src/gnuwin32/graphapp/events.c:handle_char(), \r is actively replaced
> with \n.

That's not part of R's I/O, though.

> I didn't find any specific mention of EOL/newline in "Writing R
> Extensions", and only reference to related escape sequences in "R
> Language Definition".
>
> My questions:
> - Is it safe (and indeed proper) for PL/R to always convert \r\n to
> \n prior to invoking the R parser?
> - Should the same be done for \r to \n (e.g. on OS X)?
> - Any other considerations I should care for?
>
> Thanks,
>
> Joe
>
> ______________________________________________
> 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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 20 Jun 2007 - 17:30:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Jun 2007 - 23:35:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.