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, ...); 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. -- dr. Matjaz Kukar Univerza v Ljubljani Fakulteta za racunalnistvo in informatiko Trzaska 25, 1001 Ljubljana
Matjaz Kukar <matjaz.kukar@fri.uni-lj.si> writes:> 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?Can't see anything relevant changed recently... I can see that findFun gives an error if the function is not found, which I presume is what you call a "crash". 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. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
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@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