[Rd] R-2.0.0 findVar and findFun question

Matjaz Kukar matjaz.kukar at fri.uni-lj.si
Fri Oct 8 22:53:07 CEST 2004


Prof Brian Ripley wrote:

> 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

Where can one find out what is a public R API and what isn't?

> 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.
> 

Silly me. I compressed my code a bit too much (hence the '...' you have noticed before).
Actually, the expression gets constructed as above, with the only difference that it
does not start with  SETCAR(e, install("function_name")) but with SETCAR(e, obj) where
obj = findVar(install("function_name"), R_GlobalEnv). This worked in previous versions
(1.6.2 - 1.9.1) just fine. In 2.0.0 the problem, as described before, is that findVar
returns a function object, but (in case of generic functions) the evaluation fails with
the "Error in function (object, ...)  : Invalid generic function in usemethod" error
message.

I resorted to findFun function, however Peter Dalgaard here on the list suggested using
findVar1 (which seems to be an even more obscure function than R_tryEval). I even
had to write the header file by myself, although the function works just perfectly.


> Incidentally, your code need not be littered with Rf_*; that indicates 
> you are not including the right header files.

Well, both Rf_findVar function and findVar macro are declared and defined,
respectively, in the same (Rinternals.h) file. So I'm pretty sure I'm including
the right header file :-).

It seems to me more and more that my problems don't have much to do with
findVar ... functions, but are probably a result of deeper changes, maybe
in generic function handling.

Matjaz.

-- 
dr. Matjaz Kukar
Univerza v Ljubljani
Fakulteta za racunalnistvo in informatiko
Trzaska 25, 1001 Ljubljana



More information about the R-devel mailing list