This morning I fixed some bugs a couple of the new functions to phytools that I posted about yesterday: specifically fancyTree(...,type="traitgram3d") and phylomorphospace3d. I also made one minor change to anc.ML, my function for ancestral character estimation using maximum likelihood.
The most important updates were all to the function fancyTree. First, there was a problem in the way that I was passing optional arguments to and within the function using ... (dot-dot-dot or three dots). If one has a set of optional arguments, and you just want to pass them directly to another function that is going to be call internally, then this can be done using ... as a stand-in for these arguments. For instance:
foo<-function(x,y,...) plot(x,y,...)
will pass the optional arguments in ... directly to plot (which is a generic function with many optional arguments).
In my case, though, I wanted to gather optional arguments depending on a method (to be called internally), work with the arguments, and then send them to another function. I accomplished this (I believe correctly) using hasArg and list(...). This basically works as follows:
traitgram3d<-function(tree,...,control){
if(hasArg(X)) X<-list(...)$X # get phenotypic data if provided
else stop("no phenotypic data provided")
if(!hasArg(A)){ # if ancestral states not provided
... # estimate ancestral states
} else A<-list(...)$A # otherwise get them
... # do some other stuff
phylomorphospace3d(tree,X,A,control=control) # plot
}
This seems to work, although it was somewhat difficult to find out online if this is the current best practice for optional arguments. Maybe a reader of the blog knows better!
As evidenced by the pseudocode above, fancyTree(...,type="traitgram3d") now accepts user supplied ancestral character states for internal nodes. We might have these, for instance, by simulation.
Finally, I also made some minor updates to phylomorphopsace3d (changing how the tip spheres are scaled) and anc.ML (adjusting the bound for optim(...,method="L-BFGS-B").
In addition to uploading these new function versions to the phytools page, I have also built a new package version (v 0.1-87) which can be downloaded here.
No comments:
Post a Comment
Note: due to the very large amount of spam, all comments are now automatically submitted for moderation.