Re: [Rd] Parsing code with newlines

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 04 Aug 2008 14:18:52 +0100 (BST)

This adds nothing to your previous post: please don't be annoying and post almost identical messages.

I strongly suspect you mean 'parse error' and 'how can I parse R code', but we don't know what the example was and what the error message was. Nor do we know what you are doing with this fragement of C code (and returnng an unprotected SEXP via a (void *) cast is a recipe for tears).

parse(text=) uses R_ParseVector, and that works for 'code that includes comments and newlines', so please check out the internal code used (in src/main/gram.c).

If you study the posting guide you should be able to formulate a posting that people can actually help you with.

On Mon, 4 Aug 2008, 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;
> }
> }
>
> Regards,
> Peter
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon 04 Aug 2008 - 13:37:42 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