-/* bipartition.c 2007-06-29 */
+/* bipartition.c 2012-03-26 */
-/* Copyright 2005-2007 Emmanuel Paradis, and 2007 R Development Core Team */
+/* Copyright 2005-2012 Emmanuel Paradis, and 2007 R Development Core Team */
/* This file is part of the R-package `ape'. */
/* See the file ../COPYING for licensing issues. */
SEXP prop_part(SEXP TREES, SEXP nbtree, SEXP keep_partitions)
{
- int i, j, k, l, KeepPartition, Ntree, Ntip, Nnode, Npart, NpartCurrent, *no;
+ int i, j, k, KeepPartition, Ntree, Ntip, Nnode, Npart, NpartCurrent, *no;
SEXP bp, ans, nbtip, nbnode, number;
PROTECT(nbtree = coerceVector(nbtree, INTSXP));
INTEGER(nbtip)[0] = Ntip;
INTEGER(nbnode)[0] = Nnode;
- if (KeepPartition) Npart = Ntree*(Nnode - 1) + 1;
- else Npart = Nnode;
+ if (KeepPartition) Npart = Ntree * (Ntip - 2) + 1;
+ else Npart = Ntip - 1;
PROTECT(number = allocVector(INTSXP, Npart));
no = INTEGER(number); /* copy the pointer */
/* We start on the 2nd tree: */
for (k = 1; k < Ntree; k++) {
+
+/* in case there are trees with multichotomies: */
+ nbnode = getListElement(VECTOR_ELT(TREES, k), "Nnode");
+ Nnode = INTEGER(nbnode)[0];
+
PROTECT(bp = bipartition(getListElement(VECTOR_ELT(TREES, k), "edge"),
nbtip, nbnode));
for (i = 1; i < Nnode; i++) {