[R] primitives again
    Wacek Kusnierczyk 
    Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
       
    Mon Mar 16 09:06:46 CET 2009
    
    
  
Berwin A Turlach wrote:
> On Sun, 15 Mar 2009 14:23:40 +0100
> Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
>
>   
>> Edna Bell wrote:
>>     
>>> How do I find the functions which are primitives, please?
>>>   
>>>       
>> you can scan the whole search path for functions that are primitives:
>>
>>     primitives = sapply(search(), function(path)
>>      with(as.environment(path), Filter(is.primitive, lapply(ls(),
>> get))))
>>
>> primitives is a list of named lists of primitives, one sublist for
>> each attached package (most sublists will be empty, i guess).
>>     
>
> The code above will miss some primitives in package:base, namely those
> that start with a dot:
>   
oops, right:  it should have said
    primitives = sapply(search(), function(path)     
        with(as.environment(path), Filter(is.primitive,
lapply(ls(all.names=TRUE), get))))
i was aware of this, but forgot to type it in in the mail, while it was
there in the console, hence i haven't noticed the lack of dot-primitives.
thanks for pointing this out.
>
> Also, but that is a matter of taste, it could be preferable to use
> sapply instead of lapply:
yes, indeed.
vQ
    
    
More information about the R-help
mailing list