# Function to prettify the output of current.vpTree() # Call it like this ... # formatVPTree(current.vpTree()) formatVPTree <- function(x, indent=0) { end <- regexpr("[)]+,?", x) sibling <- regexpr(", ", x) child <- regexpr("[(]", x) if ((end < child || child < 0) && (end < sibling || sibling < 0)) { lastchar <- end + attr(end, "match.length") cat(paste0(paste(rep(" ", indent), collapse=""), substr(x, 1, end - 1), "\n")) if (lastchar < nchar(x)) { formatVPTree(substring(x, lastchar + 1), indent - attr(end, "match.length") + 1) } } if (child > 0 && (sibling < 0 || child < sibling)) { cat(paste0(paste(rep(" ", indent), collapse=""), substr(x, 1, child - 3), "\n")) formatVPTree(substring(x, child + 1), indent + 1) } if (sibling > 0 && sibling < end && (child < 0 || sibling < child)) { cat(paste0(paste(rep(" ", indent), collapse=""), substr(x, 1, sibling - 1), "\n")) formatVPTree(substring(x, sibling + 2), indent) } }