Skip to content

Commit

Permalink
Shorten leaf node function (previously next_targets())
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Nov 24, 2017
1 parent 2badae8 commit 867f643
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ importFrom(grDevices,col2rgb)
importFrom(grDevices,rgb)
importFrom(igraph,V)
importFrom(igraph,adjacent_vertices)
importFrom(igraph,degree)
importFrom(igraph,delete_vertices)
importFrom(igraph,edge)
importFrom(igraph,is_dag)
Expand Down
2 changes: 1 addition & 1 deletion R/dataframes_graph_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ resolve_levels <- function(config) {
keep_these <- setdiff(V(graph)$name, rownames(nodes))
graph_remaining_targets <- delete_vertices(graph, v = keep_these)
while (length(V(graph_remaining_targets))) {
candidates <- next_targets(graph_remaining_targets, jobs = jobs)
candidates <- leaf_nodes(graph = graph_remaining_targets)
if (length(candidates)){
nodes[candidates, "level"] <- level
level <- level + 1
Expand Down
2 changes: 1 addition & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#' @importFrom formatR tidy_source
#' @importFrom future future_lapply plan
#' @importFrom grDevices col2rgb rgb
#' @importFrom igraph adjacent_vertices delete_vertices edge
#' @importFrom igraph adjacent_vertices delete_vertices degree edge
#' is_dag make_empty_graph plot.igraph subcomponent V vertex
#' @importFrom knitr knit
#' @importFrom lubridate dseconds duration
Expand Down
19 changes: 4 additions & 15 deletions R/parallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ run_parallel <- function(config, worker) {
}

parallel_stage <- function(worker, config) {
candidates <- next_targets(
config$graph_remaining_targets, jobs = config$jobs)
candidates <- leaf_nodes(graph = config$graph_remaining_targets)
meta_list <- meta_list(targets = candidates, config = config, store = TRUE)
should_build <- lightly_parallelize(
X = candidates,
Expand Down Expand Up @@ -57,19 +56,9 @@ exclude_imports_if <- function(config){
config
}

next_targets <- function(graph_remaining_targets, jobs = 1){
number_dependencies <- lightly_parallelize(
X = V(graph_remaining_targets),
FUN = function(x){
adjacent_vertices(graph_remaining_targets, x, mode = "in") %>%
unlist() %>%
length()
},
jobs = jobs
) %>%
unlist
which(!number_dependencies) %>%
names()
leaf_nodes <- function(graph){
is_leaf <- igraph::degree(graph, mode = "in") == 0
V(graph)[is_leaf]$name
}

lightly_parallelize <- function(X, FUN, jobs = 1, ...) {
Expand Down

0 comments on commit 867f643

Please sign in to comment.