Re: [R] separate commands by semicolon

2016-09-19 Thread Adrian Dușa
Oh yes, completely forgot about partial parsing. One possible (quick) solution: txt <- "print(2); bar <- \"don't ; use semicolons\"; foo <- '3;4'; ls(" sf <- srcfile("txt") tryit <- tryCatch(parse(text = txt, srcfile = sf), error = identity) gpd <- getParseData(sf) pos <- c(0, gpd$col1[gpd$token =

Re: [R] separate commands by semicolon

2016-09-19 Thread Duncan Murdoch
On 19/09/2016 7:59 AM, Adrian Dușa wrote: On Sun, Sep 18, 2016 at 12:34 AM, Peter Langfelder < peter.langfel...@gmail.com> wrote: > On Sat, Sep 17, 2016 at 2:12 PM, David Winsemius > wrote: > > Not entirely clear. If you were intending to just get character output > then you could just use: > >

Re: [R] separate commands by semicolon

2016-09-19 Thread Adrian Dușa
On Sun, Sep 18, 2016 at 12:34 AM, Peter Langfelder < peter.langfel...@gmail.com> wrote: > On Sat, Sep 17, 2016 at 2:12 PM, David Winsemius > wrote: > > Not entirely clear. If you were intending to just get character output > then you could just use: > > > > strsplit(txt, ";") > > You would want t

Re: [R] separate commands by semicolon

2016-09-17 Thread Peter Langfelder
On Sat, Sep 17, 2016 at 2:12 PM, David Winsemius wrote: > > > Not entirely clear. If you were intending to just get character output then > you could just use: > > strsplit(txt, ";") > > If you wanted parsing to an R expression to occur you could pass through > sapply and get a full accounting o

Re: [R] separate commands by semicolon

2016-09-17 Thread David Winsemius
> On Sep 17, 2016, at 8:28 AM, Adrian Dușa wrote: > > There is one minor problem with parse(): if any of the individual commands > has an error, the entire text will be parsed in a single error. > > For example, in a normal R console: > >> print(2); ls( > [1] 2 > + > > So first print(2) is ex

Re: [R] separate commands by semicolon

2016-09-17 Thread Adrian Dușa
There is one minor problem with parse(): if any of the individual commands has an error, the entire text will be parsed in a single error. For example, in a normal R console: > print(2); ls( [1] 2 + So first print(2) is executed, and only after the console expects the user to continue the comman

Re: [R] separate commands by semicolon

2016-09-15 Thread Adrian Dușa
On Thu, Sep 15, 2016 at 10:28 PM, William Dunlap wrote: > The most reliable way to split such lines is with parse(text=x). > Regular expressions don't do well with context-free grammars. > Oh, that's right of course. > as.character(parse(text = x)) [1] "foo <- \"3;4\"""bar <-

Re: [R] separate commands by semicolon

2016-09-15 Thread William Dunlap via R-help
The most reliable way to split such lines is with parse(text=x). Regular expressions don't do well with context-free grammars. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Sep 15, 2016 at 12:08 PM, Adrian Dușa wrote: > Dear R-helpers, > > When parsing a text, I would like to separate co

[R] separate commands by semicolon

2016-09-15 Thread Adrian Dușa
Dear R-helpers, When parsing a text, I would like to separate commands written on the same line, by a semicolon. Something like: x <- "foo <- '3;4'; bar <- \"don't ; use semicolons\"" Ideally, that would translate to these two commands in a character vector of length 2: foo <- '3;4' bar <- "don'