From murdoch at stats.uwo.ca  Mon Aug  4 15:11:07 2008
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Mon, 04 Aug 2008 09:11:07 -0400
Subject: [Rd] Parsing code with newlines
In-Reply-To: <a564fafa0808040550j13fd5097q804fc9549cd4ad55@mail.gmail.com>
References: <a564fafa0808040550j13fd5097q804fc9549cd4ad55@mail.gmail.com>
Message-ID: <4896FFEB.9000501@stats.uwo.ca>

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



[Rd] Parsing code with newlines
Duncan Murdoch