From ripley at stats.ox.ac.uk  Wed Apr  6 08:49:55 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed Apr  6 08:50:05 2005
Subject: [Rd] Calling do_inherit from C
In-Reply-To: <C698D707214E6F4AB39AB7096C3DE5A58FFBC1@phost015.EVAFUNDS.intermedia.net>
References: <C698D707214E6F4AB39AB7096C3DE5A58FFBC1@phost015.EVAFUNDS.intermedia.net>
Message-ID: <Pine.LNX.4.61.0504060742310.18825@gannet.stats>

On Tue, 5 Apr 2005, Vadim Ogranovich wrote:

> Hi,
>
> Is there a way (or better say idiom) for calling functions like
> do_inherit() (which are meant to be called via .Internal) from regular C
> code. Say I have a SEXP object x and I want to check if it inherits from
> "POSIXt". How do I do this?

Call eval() on the R expression you want.  There are lots of examples in 
the tests/Embedding directory, and the following (in objects.c)

#ifdef UNUSED
static void load_methods_package()
{
     SEXP e;
     R_set_standardGeneric_ptr(dispatchNonGeneric, NULL);
     PROTECT(e = allocVector(LANGSXP, 2));
     SETCAR(e, install("library"));
     SETCAR(CDR(e), install("methods"));
     eval(e, R_GlobalEnv);
     UNPROTECT(1);
}
#endif

is a simple prototype for such calls.


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


[Rd] Calling do_inherit from C
Prof Brian Ripley