-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add context class and register graph at each verb
- Loading branch information
Showing
10 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' @importFrom R6 R6Class | ||
ContextBuilder <- R6Class( | ||
'ContextBuilder', | ||
public = list( | ||
set = function(graph) { | ||
stopifnot(inherits(graph, 'tbl_graph')) | ||
private$context <- graph | ||
invisible(self) | ||
}, | ||
clear = function() { | ||
private$context <- NULL | ||
}, | ||
alive = function() { | ||
!is.null(private$context) | ||
}, | ||
graph = function() { | ||
private$check() | ||
private$context | ||
}, | ||
nodes = function() { | ||
as_tibble(self$graph, active = 'nodes') | ||
}, | ||
edges = function() { | ||
as_tibble(self$graph, active = 'edges') | ||
} | ||
), | ||
private = list( | ||
context = NULL, | ||
check = function() { | ||
if (!self$alive()) { | ||
stop('This function should not be called directly', call. = FALSE) | ||
} | ||
} | ||
) | ||
) | ||
.graph_context <- ContextBuilder$new() | ||
|
||
#' @export | ||
.G <- function() { | ||
.graph_context$graph() | ||
} | ||
#' @export | ||
.N <- function() { | ||
.graph_context$nodes() | ||
} | ||
#' @export | ||
.E <- function() { | ||
.graph_context$edges() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters