[Phylobase-devl] Proposition for phylo4d constructor
Ben Bolker
bolker at zoo.ufl.edu
Thu Aug 28 00:48:36 CEST 2008
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
phylo4d(x,...)
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 ...
:-)
Ben
François Michonneau wrote:
> Hello,
>
> 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:
>
> library(phylobase)
> ### 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
> change.
>
> Cheers,
> François
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Phylobase-devl mailing list
> Phylobase-devl at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/phylobase-devl
More information about the Phylobase-devl
mailing list