Skip to content

Commit

Permalink
Merge pull request #2 from trvinh/class2tree-replace
Browse files Browse the repository at this point in the history
fix the classification data type
  • Loading branch information
gedankenstuecke authored Oct 2, 2017
2 parents 693dc91 + 56c3f03 commit e5c7d3d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/class2tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class2tree <- function(input, varstep = TRUE, check = TRUE, ...) {
if (length(input) < 3)
stop("Your input list of classifications must be 3 or longer.")

dat <- rbind.fill(lapply(input, class2tree_helper))
# Get rank and ID list
rankList <- rbind.fill(lapply(input, getRankList))
idList <- rbind.fill(lapply(input, getIdList))
Expand All @@ -79,12 +80,19 @@ class2tree <- function(input, varstep = TRUE, check = TRUE, ...) {
if (is(taxdis, 'simpleError'))
stop("Try check=FALSE, but see docs for taxa2dist function in the vegan package for details.")
out <- as.phylo.hclust(hclust(taxdis, ...))
res <- list(phylo = out, classification = idList, distmat = taxdis,
res <- list(phylo = out, classification = dat, distmat = taxdis,
names = names(input))
class(res) <- 'classtree'
return( res )
}

class2tree_helper <- function(x){
df <- x[-nrow(x), 'name']
names(df) <- x[-nrow(x), 'rank']
df <- data.frame(t(data.frame(df)), stringsAsFactors = FALSE)
data.frame(tip = x[nrow(x), "name"], df, stringsAsFactors = FALSE)
}

#' @method plot classtree
#' @export
#' @rdname class2tree
Expand Down

0 comments on commit e5c7d3d

Please sign in to comment.