R/node_prune.R

Defines functions node_prune

Documented in node_prune

#' @export
#' @title Prune Nodes off a Tree by Names
#' @aliases node_prune
#' @description A wrapper of data.tree::Prunes. Prune nodes off a tree by names.
#' This function has side-effects, it modifies the tree given by the argument (see the package data.tree).
#' @param tree a tree (i.e. a Node object).
#' @param ... some character strings specifies the names of nodes to be pruned.
#' @return Invisibly returns the tree.
#' @examples
#' \donttest{
#' dst <- node_new(
#'   "firm",
#'   "lab", "cap", "land"
#' )
#' node_prune(
#'   dst,
#'   "cap", "land"
#' )
#' plot(dst)
#' }


node_prune <- function(tree, ...) {
  arg.list <- list(...)

  for (k in seq_along(arg.list)) {
    Prune(tree, function(x) x$name != arg.list[[k]])
  }

  invisible(tree)
}

Try the GE package in your browser

Any scripts or data that you put into this service are public.

GE documentation built on Nov. 8, 2023, 9:07 a.m.