Re: [Rd] Parsing code with newlines

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Mon, 04 Aug 2008 09:11:07 -0400

On 04/08/2008 8:50 AM, Peter Jaeger wrote:
> Dear List,
>
> When I try to parse code containing newline characters with R_ParseVector, I
> get a compilation error. How can I compile code that includes comments and
> newlines?
>
> I am using the following:
>
> void* my_compile(char *code)
> {
> SEXP cmdSexp, cmdExpr = R_NilValue;
> ParseStatus status;
>
> PROTECT (cmdSexp = allocVector (STRSXP, 1));
> SET_STRING_ELT (cmdSexp, 0, mkChar (code));
> PROTECT (cmdExpr = R_ParseVector (cmdSexp,-1,&status,
> R_NilValue));
> UNPROTECT_PTR (cmdSexp);
>
> if (status != PARSE_OK) {
> return (void*)0;
> } else {
> return (void*)cmdExpr;
> }
> }

You need to put together a reproducible example if you want help. parse() uses R_ParseVector, and it handles newlines fine.

Duncan Murdoch



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 04 Aug 2008 - 13:19:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 04 Aug 2008 - 21:35:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive