% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/node.R
\name{df_to_tree}
\alias{df_to_tree}
\title{Convert a flat data frame into a nested node tree}
\usage{
df_to_tree(
  df,
  name_col,
  value_cols,
  group_col = NULL,
  total = NULL,
  node_values = list()
)
}
\arguments{
\item{df}{A data frame.}

\item{name_col}{Column name to use as the node label (leaf rows).}

\item{value_cols}{Character vector of value column names.}

\item{group_col}{Character vector of grouping columns, outermost first.
Each element adds one nesting level. \code{NULL} returns a flat list of leaves.}

\item{total}{Optional string. When non-\code{NULL} a single root node with this
label wraps the entire tree (grand-total row). \code{NULL} for no total.}

\item{node_values}{Optional named list of pre-supplied values for group
(and total) nodes. Each name is a node label; each value is a named list
of column values that should be displayed as-is rather than rolled up from
children. Useful when aggregated figures (e.g. time-weighted returns) are
already known and differ from a simple weighted average of the leaves.

Example — supply a pre-computed return for the "Technology" sector and the
"Mag 7" grand total:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{node_values = list(
  "Technology" = list(ytd_return = 2.5),
  "Mag 7"      = list(ytd_return = 4.1)
)
}\if{html}{\out{</div>}}

Any column \emph{not} listed for a node still falls back to rollup from
children.}
}
\value{
A list of \code{\link[=node]{node()}} objects suitable for passing to \code{\link[=nestable]{nestable()}}.
}
\description{
Convert a flat data frame into a nested node tree
}
