R/de.R

Defines functions de

Documented in de

#' @title Finds all decendants of a particular node in a tree.   
#' 
#' @description This function identifies all nodes in a given tree structure
#' which are descendants of the input node. 
#' 
#' @param x node 
#' @param tree interaction tree 
#' @return Returns all the descendant nodes from the node `x`
#' @export


de <- function(x, tree)
{
  options(stringsAsFactors = FALSE)
  if(length(x) != 1) stop("The length of x in function de must be 1.")  
  y <- tree$node
  de <- NA
  if(sum(match(x, y), na.rm = T) != 0) {
    temp <- 1:length(y)
    start <- match(x, y) + 1    
    end <- length(y)
    if(start <= length(y) & nchar(y[start]) > nchar(x)) {
      temp1 <- temp[temp >= start & nchar(y) <= nchar(x)][1] - 1
      if(!is.na(temp1)) end <- temp1
      de <- y[start:end]
    }}
  de
}
kdoub5ha/mvITR documentation built on April 7, 2020, 3:59 a.m.