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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to