-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ac6233
commit d37d749
Showing
19 changed files
with
435 additions
and
183 deletions.
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
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,37 @@ | ||
#' @title Save the graph into a binary blob | ||
#' @param graph A graph object | ||
#' @param path Path to a file to save the graph into | ||
#' @return Run for its side-effects | ||
#' @export | ||
graph_to_bin <- function(graph, path) { | ||
if (missing(path)) { | ||
return(graph$to_bin_mem()) | ||
} | ||
graph$to_bin_disk(path) | ||
} | ||
|
||
#' @title Read the graph from a binary blob | ||
#' @param path Path to a file containing a graph binary | ||
#' @param type The type of graph the JSON represents | ||
#' @return A graph object | ||
#' @export | ||
graph_from_bin <- function(path, bin, type = c("directed", "dag")) { | ||
if (!type[1] %in% c("directed", "dag")) { | ||
rlang::abort("Invalid argument `type`") | ||
} | ||
if (!missing(bin)) { | ||
switch( | ||
type[1], | ||
"directed" = DirectedGraph$from_bin_mem(bin), | ||
"dag" = DirectedAcyclicGraph$from_bin_mem(bin) | ||
) | ||
} | ||
if (missing(path)) { | ||
rlang::abort("Must provide `path` or `bin` arguments") | ||
} | ||
switch( | ||
type[1], | ||
"directed" = DirectedGraph$from_bin_disk(path), | ||
"dag" = DirectedAcyclicGraph$from_bin_disk(path) | ||
) | ||
} |
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
Oops, something went wrong.