jinyizju / V.PhyloMaker

This R package makes phylogenetic hypotheses for a user-specified list of species at a faster speed than S.PhyloMaker
32 stars 12 forks source link

factors in dataframes caused error in build.nodes. #6

Closed gowachin closed 4 years ago

gowachin commented 4 years ago

Hello,

I've found an error in the manual and I think some functions were broken. Factors cause this error from the example in man for build.nodes.1 :

#### Example from the man ####
# make the tree and its tips information
phylogeny <- rcoal(10)  # generate a phylogeny with 10 tips
phylogeny$node.label <- paste("N",1:phylogeny$Nnode,sep="")  # label the nodes
phylogeny$tip.label <- paste(rep(rep(c("Genus1","Genus2"),2),4:1), phylogeny$tip.label, sep="_")   # rename the tips
tips <- data.frame(species = phylogeny$tip.label,genus=rep(rep(c("Genus1","Genus2"),2),4:1),family=rep(rep(c("Family1","Family2"),2),4:1)) # generate the tips information

# plot the tree
plot(phylogeny, show.node.label=TRUE, tip.color=rep(rep(c("black","red"),2),4:1),edge.width=1)

# generate the nodes information of the tree
nodes.inf<-build.nodes.1(phylogeny, tips)   # build the nodes information file for the phylogeny
# Error in if (n > min(tree$edge[, 1])) { : 
# length is null
# Also : Warning message:
# In `[<-.factor`(`*tmp*`, i, value = "N1") :
#  invalid factor level, NA generated
nodes.inf   # show the nodes.infomation file

I modified the data.frame formation in build.nodes.1 to force the absence of factors, by inserting stringAsFactors = FALSE. I suspect that some user have different default.stringsAsFactors() values in their R and forcing it in this function could secure the process.

Note that I didn't modify build.nodes.2 but it return the same error so I expect my solution to work in it as well.

I hope this modification didn't affect the result of the function, as there was no (small) data in the package to compare the output for a tree with 10 tips.

Thanks anyway for your package, it is helping my actual work. Best regards,

Maxime Jaunatre

jinyizju commented 4 years ago

Thanks, Maxime, for pointing out the errors, they escaped my notice last time I changed the global environmental settings as suggested by another user. Your suggestions are adopted and the errors are fixed.