SCM

[#571] Implement replace method to update value of a subset of nodes

Date:
2009-08-17 00:08
Priority:
3
State:
Open
Submitted by:
François Michonneau (francois)
Assigned to:
Nobody (None)
Target Version:
None
Summary:
Implement replace method to update value of a subset of nodes

Detailed description
We should implement a method to update a subset of nodes.

Which approache(s) should we use?
- S3 style: nodeLabels(foo)["4"] <- "bar"
- S4 style: nodeLabels(foo, 4) <- "bar"

I prefer the latter.

Comments:

Message  ↓
Date: 2009-09-30 11:13
Sender: François Michonneau

My concern with this was that a method was needed to make sure that the validator was applied. I was also concerned with the fact that the order of the elements may not have always been consistent and this approach may have been confusing for the users.
However, with the implementation of the new object structure that the second part shouldn't be too much of a problem. Furthermore, the "native" implementation of the replace method is probably good enough for now. We may want to write these methods at some point though.
PS: I agree that, if it's easy to fix, tdata<- shouldn't affect the other part of the data.

Date: 2009-09-29 23:38
Sender: Jim Regetz

For what it's worth, the former works already for labels, tipLabels, nodeLabels, edgeLabels, and edgeLength. Example:

set.seed(1)
phy <- phylo4(rtree(5))
nodeLabels(phy)
## 6 7 8 9
## NA NA NA NA

nodeLabels(phy)["7"] <- "x"
nodeLabels(phy)
## 6 7 8 9
## NA "x" NA NA

nodeLabels(phy)[3] <- "y"
nodeLabels(phy)
## 6 7 8 9
## NA "x" "y" NA


Moreover, you can update data values with tdata using code like this:

data(geospiza)
tdata(geospiza, "all")["olivacea", "wingL"] <- 500

but note that if you add/change any data using one of the types "tip" or "internal" (as opposed to "all"), any existing data for the other type are lost:

data(geospiza)

hasTipData(geospiza)
## [1] TRUE
hasNodeData(geospiza)
## [1] FALSE

# now add some internal node data
tdata(geospiza, "internal")["N21", "wingL"] <- 5

hasTipData(geospiza)
## [1] FALSE
hasNodeData(geospiza)
## [1] TRUE

I imagine it would be good to change this behavior. Probably better for tdata<- to behave like labels<-, insofar as modifying the values for one of tips or internals shouldn't have any effect on the other.

Date: 2009-08-17 00:13
Sender: Peter Cowan

+1 for the latter

Attached Files:

Changes

No Changes Have Been Made to This Item

Thanks to:
Vienna University of Economics and Business Powered By FusionForge