[Rd] Wish: C-API to get parse error messages (PR#9466)

thomas.friedrichsmeier at ruhr-uni-bochum.de thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Jan 25 17:05:34 CET 2007


Full_Name: Thomas Friedrichsmeier
Version: 2.4.1
OS: Linux
Submission from: (NULL) (84.61.205.78)


Currently, the C-API provides for parsing vectors (R_ParseVector()), but there
does not seem to be a way to get at the detailed parse error message from C.
Only a status code is returned, no error message.

In the internal code, the function parseError() is responsible for producing
such an error message. It would be very helpful, if this function could be made
available - directly or indirectly - in the public API. Some more background
information is available at
https://stat.ethz.ch/pipermail/r-devel/2007-January/044336.html.

Below are several alternative suggestions on different ways to add this:

1) Simply make parseError(SEXP call, int linenum) public API (currently not in
the public headers, and not visible in the library).

2) To hide the details of parseError(), instead a wrapper could be created and
made available like e.g.:
void Rf_parseErrorDefault()
{
    parseError(R_NilValue, 0);
}

3) It might be desirable to make parsing and producing the error an atomic
operation to embedding code, in order to guard against race conditions, if there
might be concurrent parses in the future. E.g. provide and export the
following:
SEXP R_ParseVectorWithError(SEXP exp, int num, ParseStatus *status, SEXP file)
{
    SEXP pr;
    pr = R_ParseVector(exp, num, status, file);
    if(status == PARSE_ERROR)
      parseError(R_NilValue, 0);
    return pr;
}

4) Finally, if this wish has any chance of being fulfilled until R 2.5.0,
production of a parse error could be made an additional parameter of
R_ParseVector() (since R_ParseVector() has already gained a new parameter since
2.4, so there would be no additional API breakage):
SEXP R_ParseVector(SEXP exp, int num, ParseStatus *status, SEXP file, Rboolean
doerror);

Regards
Thomas Friedrichsmeier



More information about the R-devel mailing list