[Rd] [R] Continuation and parse

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jul 20 18:16:25 CEST 2006


The issue here is that the current expression is still there and 
protected if there is a parse problem.  So you need one more unprotect.

This does not give a problem in source() (the only internal use) as it 
throws an error in those cases.  (It also uses a different branch of the 
code with n < 0.)

Since this seems to be worrying no one else, I am going to add the 
unprotect in the source code for R-devel.

On Thu, 13 Jul 2006, Martin Morgan wrote:

> [this is from R-help, at the end of June]
> 
> Jim Lemon asked about parsing syntactically incorrect versus
> incomplete lines, generating a couple of responses.
> 
> Philippe's suggestion isn't robust (e.g., "\nls)". Prof. Ripley's
> comment lead me to R_ParseVector (the only exposed parse
> routine). Unfortunately, this returns from parsing incomplete or
> syntactically incorrect text with a PROTECT stack imbalance, so there
> is no natural way to return from a .Call.
> 
> What I'd like is to have access to multiline console input after
> parsing but before evaluation, or to return from a .Call like that
> below with either the parsed expression or information about the
> reason for failure. Any suggestions?
> 
> Thanks in advance,
> 
> Martin
> 
> SEXP parses(SEXP cmd) {
>   ParseStatus status;
>   SEXP res;
>   res = R_ParseVector(cmd, 1, &status);
>   return res;
> }
> 
> /* > .Call("parses", "ls(") */
> /* 25        SEXP res = R_ParseVector(cmd, 1, &status); */
> /* (gdb) p R_PPStackTop */
> /* $1 = 3 */
> /* (gdb) next */
> /* 26        return res; */
> /* (gdb) p R_PPStackTop */
> /* $2 = 5 */
> 
> R version 2.4.0 Under development (unstable) (2006-07-11 r38560)
> x86_64-unknown-linux-gnu
> 
> Philippe Grosjean <phgrosjean at sciviews.org> writes:
> 
> > Well, you haven't used the search engines with the right key: the magic 
> > words are:
> >
> >  > RSiteSearch("incomplete line")
> >
> > With the first document being my query (almost two years ago), and the 
> > second one being Peter Dalgaard answer. You must adapt it to cope with 
> > internationalization, but basically, you could use something like:
> >
> >  > grep("\n2:",try(parse(textConnection("ls)")), silent = TRUE))
> > numeric(0)
> >  > grep("\n2:",try(parse(textConnection("ls(")), silent = TRUE))
> > [1] 1
> 
> From: Prof Brian Ripley <ripley>
> Date: Wed, 28 Jun 2006 13:44:49 +0100 (BST)
> 
> On Wed, 28 Jun 2006, Jim Lemon wrote:
> 
> > Hi gurus,
> >
> > After an unsuccessful scrabble through the documentation and Jon's
> > excellent search facility, I am no wiser as to how R recognizes an
> > incomplete command line and politely raises its hand for more. The help
> > page for parse gives no indication that it does anything more than spit
> > the dummy when fed an incomplete command line, but something in there
> > must recognize such ellipsis. Any hints?
> 
> It's internal. Look in src/main/main.c, in particular the R_Repl*
> functions. In short, R_Parse1Buffer can return PARSE_INCOMPLETE.
> 
> ______________________________________________
> 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



More information about the R-devel mailing list