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 <dwinsem...@comcast.net>
> wrote:
> > Not entirely clear. If you were intending to just get character output
> then you could just use:
> >
> > strsplit(txt, ";")
> You would want to avoid splitting within character strings
> (print(";")) and in comments (print(2); ls() # This prints 2; then
> lists...) The comment char could also appear in a character string,
> where it does not mean the start of a comment...

Yes, that would be the problem.
Returning to my original post, modifying the example:

x <- "print(2); bar <- \"don't ; use semicolons\"; foo <- '3;4'; ls("

This should result in a character vector of length 4:
[1] "print(2)"                          "bar <- \"don't ; use semicolons\""
[3] "foo <- '3;4'"                      "ls("

even though the last command would cause an error using parse(text = x)

Perhaps this is not that important (I am trying to simulate a normal R
console), and parse only if it syntactically correct.
I was merely curious if this could be done, likely using regular
expressions (surely strsplit doesn't solve it).


See the section on "partial parsing" in the ?parse help page.

Duncan Murdoch

R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to