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, ";") > > 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 ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.