From matjaz.kukar at fri.uni-lj.si  Fri Oct  8 22:21:32 2004
From: matjaz.kukar at fri.uni-lj.si (Matjaz Kukar)
Date: Fri Oct  8 22:49:20 2004
Subject: [Rd] R-2.0.0  findVar and findFun question
In-Reply-To: <x2655ljqy6.fsf@biostat.ku.dk>
References: <41667851.7020806@fri.uni-lj.si> <x2655ljqy6.fsf@biostat.ku.dk>
Message-ID: <4166F6CC.4040400@fri.uni-lj.si>

Peter Dalgaard wrote:

  >
> Can't see anything relevant changed recently...
> 

Well, the visible change for me was that findVar now for generic functions
does not return the correct object, and so findFun should be used. Although
this is probably a consequence of some deeper change.

> I can see that findFun gives an error if the function is not found,
> which I presume is what you call a "crash". 

Not really. On WinXP this crash was access violation in some system code.

> However, your workaround
> wouldn't catch the situation where a variable exists, but none of the
> versions in the search path are functions.
> I think you want to use findVar1() instead.
> 

Indeed. Thank you for this tip. Although so far I didn't run into such
a situation, I changed the code to the following:

// First we try to find a function with a given name
   obj = findVar1(Rf_install(ident), R_GlobalEnv, FUNSXP, TRUE);
// If there is no function, anything else will do
   if (obj == R_UnboundValue)
       obj = findVar1(Rf_install(ident), R_GlobalEnv, ANYSXP, TRUE);

The resulting object is stored and later used to construct a SEXP
used in R_tryEval(...). Only here an application should (and now,
thanks to your advice, does) complain if there is something wrong.

I suppose, FUNSXP means functions (Rinternals says "Closure or Builtin"),
and ANYSXP means anything. Should inherits (last) parameter be used as TRUE?

Could you point me to some relevant documentation concerning R API? The
"standard" documentation is often not detailed enough.


All the best,

Matjaz.

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


[Rd] R-2.0.0 findVar and findFun question
Matjaz Kukar