[R] subsetting from C code, do_subset

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Apr 22 21:57:49 CEST 2006


On Sat, 22 Apr 2006, Gabor Csardi wrote:

> On Sat, Apr 22, 2006 at 07:33:56PM +0100, Prof Brian Ripley wrote:
>> On Sat, 22 Apr 2006, Gabor Csardi wrote:
>>
>>> Dear List,
>>>
>>> do you know a way for subsetting an R object from C code? I would need the
>>> equivalent of x[s]. I've found that the do_subset internal function does
>>> this, but don't really know how to call it properly. I've two SEXP's, one
>>> for the object and one for the index.
>>>
>>> I'm thinking of creating an enviroment, place the two SEXP's in it and then
>>> just parse and run the corresponding R code, but there might be simpler
>>> way...
>>
>> That's overkill.  You know where your objects are so you can set up a call
>> with e.g. lang2 and eval it in the right place.  The code for e.g. optim
>> might give you some ideas.
>
> Thanks, i've checked the optim code. The only difference is that i don't
> have a function or expression object for '[' itself, and i couldn't manage
> to find a public entry point which can create one for me.

install("[")

>
>> do_subset is not a public entry point, and may well not be visible to
>> you in R >= 2.3.0.
>
> That is true, it is better to extract the entry from R_FunTab then?
> Of course i don't need this if i use eval, lang2, etc. But for that i need a
> function which can create a function object for '[', something like do_call,
> but do_call is not a public entry point either....
>
>> [I'd say this was an R-devel question, BTW.]
>
> Maybe. I've posted it here because i don't want to 'develop' R, only use it
> as a user. But you're right that most people here might be not interested in
> R internals.... I there was an R-help-advenced list i would have posted it
> there.
>
> Gabor
>
> [...]
>
>

-- 
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-help mailing list