FW: [Rd] Parsing multi-line strings. Bug? Feature?

Mark.Bravington at csiro.au Mark.Bravington at csiro.au
Thu Sep 16 05:21:07 CEST 2004

>  Kevin Wright <kwright at eskimo.com> writes:
>  > R 1.9.1 requires multi-line strings to contain a backslash at the
>  > end of each line (except the last line).  As noted by Mark
>  > Bravington (http://tolstoy.newcastle.edu.au/R/help/02b/5199.html)
>  > this requirement appears to be undocumented.
>  > 
>  > In S-Plus 6.2, multi-line strings do not need a backslash for continuation.
>  > 
>  > I recently (http://tolstoy.newcastle.edu.au/R/devel/04b/0256.html)
>  > requested compatability with S-Plus and was told to contribute
>  > a patch and then it would be considered.  Here is the proposed patch.


>  > Thanks for considering this patch.
> Peter Dalgaard wrote:

>  Sorry, I don't think that is good enough (notwithstanding the
>  nonstandard comment character). Notice that Splus does this:
>  > x <- "foo
>  Continue string: bar
>  Continue string: baz"
>  (and the entry is interruptible with Ctrl-C too)
>  There's a very good reason for the change of prompt, as anyone who has
>  debugged SAS code with stray quotes will tell you: The system would
>  appear to be completely unresponsive because all input is being eaten
>  by the string readers.

I think the following patch in StringValue might address Peter Dalgaard's point: when a bare newline is found (i.e. not preceded by a backslash), it's pushed back onto the character stack via xxungetc(c) and StringValue pretends that it's just read a backslash instead. Then, as usual, it looks for the next character which is of course a newline, and proceeds as normal.

Output is from diff gram.c on R-devel from 7/9/2004. I hope the comments look sufficiently standard now (I'm not a C programmer).


>           /* Old behaviour was: return ERROR; */
>           /* Now pretend there was a backslash before EOL */
<           return ERROR;
>           c = '\\';



Mark Bravington
PO Box 1538
Castray Esplanade
TAS 7001

phone (61) 3 6232 5118
fax (61) 3 6232 5012
Mark.Bravington at csiro.au

More information about the R-devel mailing list