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. This is not done by the R-level function parse(): that parses a whole buffer rather than a line at a time, and maps all non-OK results to an error. -- 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
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 Best, Philippe Grosjean ..............................................<?}))><........ ) ) ) ) ) ( ( ( ( ( Prof. Philippe Grosjean ) ) ) ) ) ( ( ( ( ( Numerical Ecology of Aquatic Systems ) ) ) ) ) Mons-Hainaut University, Belgium ( ( ( ( ( .............................................................. 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? > > Jim > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
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? Jim
[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] 1From: 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.