[Rd] Parsing code with newlines
Duncan Murdoch
murdoch at stats.uwo.ca
Mon Aug 4 15:11:07 CEST 2008
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
More information about the R-devel
mailing list