[Phylobase-devl] Proposition for phylo4d constructor
francois.michonneau at gmail.com
Mon Sep 1 23:50:16 CEST 2008
If it's not technically allowed to have a constructor for an object
of the same class, then I don't think my code should be added as it was.
I thus modified what I initially wrote.
I submitted to r-forge a new version of the 'phylo4d' constructor.
It's now possible to attach at the same time several kind of data (i.e.
tip.data, node.data and/or all.data). I also updated the documentation
and added some examples. I tested the new constructor with different
type of data combinations, but if you can, take a minute to test it with
your own data to make sure that you obtain the result you expect.
Following Ben's suggestion, I also added an error message if you're
trying to use the constructor on a phylo4d object.
You can download the source of phylobase including my modifications
I built it on my computer (linux i686 32 bits) for which the build
process doesn't fail.
Hopefully, this time my code will behave as "might be expected" :)
Ben Bolker wrote:
> On a *very* quick glance (and having heard a bit about this
> from you in person), I think your code is worth adding. Just to be
> pedantic, I think I would argue that the current behavior of the
> constructor is "as might be expected" -- that is, the constructor is
> defined as
> where x is "an object of class 'phylo4', 'phylo' or a matrix
> of edges" -- i.e., *not* class 'phylo4d'. Since x isn't
> technically allowed to be class phylo4d, the behavior
> is undefined. If we don't add your code, we should add
> a check (and error) that makes sure that x really
> is one of the allowed object types.
> There is a "tdata<-" method which works as follows:
> tdata(rTdA,"tip") <- rDt
> However, as I said I think your approach (appropriately
> documented) is fine.
> PS: you know you're turning into a cuRmudgeon when
> you spend your time explaining why R's behavior is *exactly*
> what one would logically expect after spending a few hours
> delving into the details of the R language definition ...
> François Michonneau wrote:
>> As the phylo4d constructor is currently implemented, I don't think
>> it's possible to directly add tip data, node data or both to a phylo4d
>> object. If you do:
>> ### create a tree and some data
>> ## create a tree
>> rTr <- rcoal(20)
>> rTP <- as(rTr, "phylo4")
>> ## create tip data
>> rDt <- data.frame(trait1 = rnorm(20), trait2 = rnorm(20))
>> rownames(rDt) <- labels(rTP)
>> ## create node data
>> rDn <- data.frame(trait1 = rnorm(19), trait2 = rnorm(19))
>> rownames(rDn) <- nodeLabels(rTP)
>> ## create all data
>> rDa <- data.frame(trait1 = rnorm(39), trait2 = rnorm(39))
>> rownames(rDa) <- c(paste("t", 1:20, sep=""), nodeLabels(rTP))
>> ## create a phylo4d object
>> rTdA <- phylo4d(rTP, all.data=rDa)
>> ## try to add tip data to rTda
>> rTdAt <- phylo4d(rTdA, tip.data=rDt)
>> then rTdAt contains only the newly added tip data and the "all.data"
>> previously stored are overridden.
>> I started during the summer course at NESCent to write a new method
>> for the phylo4d constructor which deals with phylo4d objects. In the new
>> version of the code I propose, you can directly add data to a phylo4d
>> object. It's also possible to add at the same time tip.data, node.data
>> and all.data. To use this new method, the data provided as arguments in
>> the constructors must have names that match (at least partially) tip
>> and/or node labels.
>> After you sourced the new method, you can try for instance:
>> (rTdAt <- phylo4d(rTdA, tip.data=rDt))
>> (rTdAatn <- phylo4d(rTdA, all.data=rDa, node.data=rDn, tip.data=rDt))
>> If you think that this new method will be useful I'll commit it to
>> SVN and update the documentation.
>> I'm also interested in feedback if you think that there are things to
>> Phylobase-devl mailing list
>> Phylobase-devl at lists.r-forge.r-project.org
More information about the Phylobase-devl