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: chk.phylo<-function(x){ object<-capture.output(checkValidPhylo(x)) if(length(grep("FATAL",object))>0) return(2) else if(length(grep("MODERATE",object))>0) return(1) else return(0) } E.g.: library(ape) t1<-rtree(n=10) chk.phylo(t1) ## should return 0 t2<-t1 t2$Nnode<-9.5 chk.phylo(t2) ## should return 1 t3<-t1 t3$edge<-t3$edge[-4,] 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): https://www.umb.edu/academics/caps/international/biology_chile On 11/5/2019 5:54 PM, Elizabeth Purdom wrote: > [EXTERNAL SENDER] > > Hello, > > 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. > > Thanks, > Elizabeth Purdom > _______________________________________________ > R-sig-phylo mailing list - R-sig-phylo@r-project.org > https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-phylo&data=02%7C01%7Cliam.revell%40umb.edu%7C6584f4bb63dd48f9205008d762326164%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637085840853226654&sdata=48LVGO%2FHHvX0rpMy6FaVgIhoeV6UO8Ouc%2B6FUfJcFCM%3D&reserved=0 > Searchable archive at > https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F&data=02%7C01%7Cliam.revell%40umb.edu%7C6584f4bb63dd48f9205008d762326164%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637085840853226654&sdata=qgug0JIrKlC9fpr8lqrMuBku2XpHV3hfbzPF0m8ByuI%3D&reserved=0 > _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/