Skip to content

Instantly share code, notes, and snippets.

@goldingn
Created September 25, 2018 09:16
Show Gist options
  • Save goldingn/6440ce27005666cba9adbe6d957827c3 to your computer and use it in GitHub Desktop.
Save goldingn/6440ce27005666cba9adbe6d957827c3 to your computer and use it in GitHub Desktop.
recursive function to find all the data nodes on which an operation node depends (up until some stopping nodes) - not required, but stashed here in case some of the ideas are
# recursively find all the data nodes that this one depends on, stopping the
# search at any nodes that are data or whose unique names are in stop_at
required_data_nodes <- function (node, stop_at = c(), data_nodes = list()) {
name <- node$unique_name
if (!name %in% stop_at) {
# if a data node, record and stop this search branch (data has no children)
if (inherits(node, "data_node")) {
data_nodes[[name]] <- node
} else {
# recurse through the children of this
# node updating the data node list
data_node_list <- lapply(node$children, required_data_nodes, stop_at, data_nodes)
# combine and remove duplicates
data_nodes <- do.call(c, data_node_list)
data_nodes <- data_nodes[!duplicated(names(data_nodes))]
}
}
data_nodes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment