[R] separate commands by semicolon
Peter Langfelder
peter.langfelder at gmail.com
Sat Sep 17 23:34:00 CEST 2016
On Sat, Sep 17, 2016 at 2:12 PM, David Winsemius <dwinsemius at comcast.net> 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 of the syntactic deficit using `try`:
>
> sapply(strsplit( "print(2); ls(" , ";")[[1]] , function(t) {try(parse(text=t))})
> Error in parse(text = t) : <text>:2:0: unexpected end of input
> 1: ls(
> ^
> expression(`print(2)` = print(2), ` ls(` = "Error in parse(text = t) : <text>:2:0: unexpected end of input\n1: ls(\n ^\n")
>
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...
Not sure how to accomplish that using strsplit (or in general using
just regular expressions).
Peter
More information about the R-help
mailing list