To answer Elizabeth's question: there is no function that does what you asked for in your first message. Liam's solution is certainly the best solution for the moment. I'll have a look at it later. The code checkValidPhylo() needs to be dusted off a bit: the diagnostic " MODERATE: some nodes are of degree 1 or less" is no more useful since nodes of degree 1 are now supported in ape.



Tue, 5 Nov 2019 14:45:58 -0800 Elizabeth Purdom <epur...@stat.berkeley.edu>:
Thank you very much, I’ll try that!

On Nov 5, 2019, at 2:20 PM, Liam Revell <liam.rev...@umb.edu> wrote:

Hi Elizabeth.

This does not do exactly what you want, but it is possible to use capture.output() to grab the printout of checkValidPhylo() and then grep() to see if it contains instances of "MODERATE" or "FATAL" errors.

The following simple function does that. It returns 0 if neither MODERATE nor FATAL errors are detected in the "phylo" object, 1 if at least one MODERATE error (but no FATAL errors) is detected, and 2 if any FATAL errors are detected:

        if(length(grep("FATAL",object))>0) return(2)
        else if(length(grep("MODERATE",object))>0) return(1)
        else return(0)




chk.phylo(t1) ## should return 0


chk.phylo(t2) ## should return 1


chk.phylo(t3) ## should return 2

All the best, Liam

Liam J. Revell
Associate Professor, University of Massachusetts Boston
Profesor Asistente, Universidad Católica de la Ssma Concepción
web: http://faculty.umb.edu/liam.revell/, http://www.phytools.org

Academic Director UMass Boston Chile Abroad (starting 2019):

On 11/5/2019 5:54 PM, Elizabeth Purdom wrote:


I am working with the phylo object from the ape package in my own package in which I am manipulating the trees. I would like to check that I have successfully created a valid ape object, but the `checkValidPhylo` function appears to be solely interactive — it prints out a display, and always returns NULL.

Is there a function in the ape package (or can there be?) that would do the checks, but return the results in a way that I can then process in my function? (e.g. return a vector of each of the checks as TRUE/FALSE) And I don’t want anything printed out, since I don’t want that output to be printed for users of my function).

I see the package `paleotree` has ported some of those checks into a test, so I’m guessing such a function doesn’t exist in ape — and I don’t really want a dependency on another package just for these checks.

Elizabeth Purdom
R-sig-phylo mailing list - R-sig-phylo@r-project.org
Searchable archive at https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F&amp;data=02%7C01%7Cliam.revell%40umb.edu%7C6584f4bb63dd48f9205008d762326164%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637085840853226654&amp;sdata=qgug0JIrKlC9fpr8lqrMuBku2XpHV3hfbzPF0m8ByuI%3D&amp;reserved=0

R-sig-phylo mailing list - R-sig-phylo@r-project.org
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

R-sig-phylo mailing list - R-sig-phylo@r-project.org
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

Reply via email to