- PROTECT(phy = allocVector(VECSXP, 4));
- SEXP root_edge;
- decode_edge(x, ps + 1, n - 2, &tmpi, &tmpd);
- PROTECT(root_edge = allocVector(REALSXP, 1));
- REAL(root_edge)[0] = tmpd;
- SET_VECTOR_ELT(phy, 3, root_edge);
- UNPROTECT(1);
- } else PROTECT(phy = allocVector(VECSXP, 3));
+ i = ps + 1;
+ while (i < n - 2 && x[i] != ':') i++;
+ if (i < n - 2) {
+ PROTECT(phy = allocVector(VECSXP, 5));
+ SEXP root_edge;
+ decode_internal_edge(x, ps + 1, n - 2, lab, &tmpd);
+ PROTECT(root_edge = allocVector(REALSXP, 1));
+ REAL(root_edge)[0] = tmpd;
+ SET_VECTOR_ELT(phy, 4, root_edge);
+ UNPROTECT(1);
+ SET_STRING_ELT(node_label, 0, mkChar(lab));
+ } else {
+ extract_portion_Newick(x, ps + 1, n - 2, lab);
+ SET_STRING_ELT(node_label, 0, mkChar(lab));
+ PROTECT(phy = allocVector(VECSXP, 4));
+ }
+ } else PROTECT(phy = allocVector(VECSXP, 4));