[R] Discovering methods

Duncan Murdoch dmurdoch at pair.com
Mon Dec 1 19:30:37 CET 2003


On Mon, 1 Dec 2003 07:15:47 -0800 (PST), Thomas Lumley
<tlumley at u.washington.edu> wrote :

>On Sun, 30 Nov 2003, Gabor Grothendieck wrote:
>
>>
>>
>> Thanks.  I guess we have to be content to approximate this via:
>>
>>    apropos("POSIXt$|POSIXct$")
>>
>> although this supposes we know that POSIXct inherits from POSIXt
>> and its not clear that there is a reliable way to discover that
>> for S3 classes.
>
>It's actually easier for S3 classes, since there it is objects that
>inherit, not classes: eg
>
>> class(.leap.seconds)
>[1] "POSIXt"  "POSIXct"

But then the obvious guess at what Gabor wants doesn't work:

>> apropos(class(.leap.seconds))
> [1] ".__C__POSIXt"        "-.POSIXt"            "+.POSIXt"           
> [4] "as.character.POSIXt" "cut.POSIXt"          "diff.POSIXt"        
> [7] "hist.POSIXt"         "julian.POSIXt"       "Math.POSIXt"        
>[10] "months.POSIXt"       "Ops.POSIXt"          "quarters.POSIXt"    
>[13] "round.POSIXt"        "seq.POSIXt"          "str.POSIXt"         
>[16] "trunc.POSIXt"        "weekdays.POSIXt"    
>Warning messages: 
>1: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>2: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>3: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>4: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>5: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>6: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>7: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>8: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>9: the condition has length > 1 and only the first element will be used in: if (is.na(pattern)) { 
>> 

What works is this:

 apropos(paste(class(.leap.seconds),'$',sep='',collapse='|'))

Duncan Murdoch




More information about the R-help mailing list