[Phylobase-devl] [Fwd: Re: labels() and other questions]

Peter Cowan pdc at berkeley.edu
Mon Mar 3 04:42:23 CET 2008


On Mar 2, 2008, at 2:20 PM, Steve Kembel wrote:
> I don't feel like the function overload is that bad yet, and this
> would be a function used primarily by programmers, so I'd vote to
> leave the existing function. It's nicer to read/write
> if(hasNodeLabels) than if(length(NodeLabels(foo))== 0).

I agree we aren't overburdened yet, but I guess I was also questioning  
how often this would come up, especially if we are forcing there to be  
default node labels.

>> How about:
>> getnode(phy,x)  which returns a named vector of node numbers;
>> if x is an integer, it matches by number, while if x is
>> a character, it matches by name?
>
> Combining the getNodeyLabel/getLabelByNode is a great idea.
>
> I went ahead and changed the labels method to return either tip,
> internal node or all labels, depending on the which argument. The
> default is still tips only so it shouldn't break anything. I couldn't
> figure out how to modify the <- method for labels to accept an
> argument, and noticed that currently there's no checking when
> assigning new labels to a phylo4 object, added this to the TODO.
>
> i.e. how can you add an argument for the generic labels<- method, or
> is this even possible:
> labels(x) <- c(which="node","Node1","Node2","Node3")

I thought you could do something along the lines of:

labels(x, which = "node") <- c("Node1","Node2","Node3")

but, I played around with it for bit and couldn't get it to work,  
perhaps some else can?

I would guess that it would be something along the lines of:

setMethod("labels<-","phylo4", function(object, which, ...,value) {

     slot(object, paste(which, 'label', sep = ".") <- value
     object
})

This of course, I was unable to get to work, and shortly became  
frustrated with the R documentation for S4 classes :)

Peter


More information about the Phylobase-devl mailing list