[Rd] R-2.0.0 findVar and findFun question
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Oct 8 16:53:25 CEST 2004
On Fri, 8 Oct 2004, Matjaz Kukar wrote:
> Dear all,
>
> when working on a project with embedded R, I found out that R-2.0.0 causes
> a problem where older versions worked OK.
>
> Rf_findVar(...) causes the following error when used to find a generic function
> (such as print):
>
> fun = Rf_findVar(...);
> R_tryEval(fun, ...);
I think without knowing what you are putting in '...' this is impossible
to understand. R_tryEval() does not seem to be part of the public API and
I had to grep the sources to find it. However, it seems to be intended to
evaluate an expression not a function, as in (tests/Embedding/tryEval.c)
PROTECT(e = allocVector(LANGSXP, 2));
SETCAR(e, Rf_install("sqrt"));
SETCAR(CDR(e), NEW_CHARACTER(1));
val = R_tryEval(e, NULL, &errorOccurred);
and it is possible that 2.0.0 is detecting an incorrect usage that 1.9.1
did not detect.
Incidentally, your code need not be littered with Rf_*; that indicates
you are not including the right header files.
> Error in function (object, ...) : Invalid generic function in usemethod
>
> Alternatively, using Rf_findFun(...) seems OK in this context, but crashes if you
> call it with an unexisting function name. Rf_findVar does not crash in this case,
> but returns an unbound value.
>
> My workaround for now is as follows:
>
> fun = Rf_findVar(Rf_install(ident), R_GlobalEnv);
> if (fun != R_UnboundValue) {
> fun = Rf_findFun(Rf_install(ident), R_GlobalEnv);
> R_tryEval(fun, ...);
> }
>
> I did some checking on the R object pointers and indeed for generic functions
> Rf_findFun and Rf_findVar return different pointers (and therefore different
> function objects).
>
> What has changed with these functions? Can you comment on my workaround
> and suggest a better (proper?) way of doing this?
>
> Platform: Windows XP, R-2.0.0, MS VSC++ 7.0
>
> Matjaz.
>
>
--
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
More information about the R-devel
mailing list