Skip to content

Commit

Permalink
Merge pull request #498 from olivroy/follow
Browse files Browse the repository at this point in the history
Update to testthat 3rd edition
  • Loading branch information
rich-iannone authored Oct 11, 2023
2 parents 1139f8c + 8c268f2 commit fd77d85
Show file tree
Hide file tree
Showing 137 changed files with 296 additions and 366 deletions.
34 changes: 18 additions & 16 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ Package: DiagrammeR
Title: Graph/Network Visualization
Version: 1.0.10.9000
Authors@R:
person("Richard", "Iannone", , "[email protected]", c("aut", "cre"),
person("Richard", "Iannone", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-3925-190X"))
Description:
Build graph/network structures using functions for stepwise addition and
deletion of nodes and edges. Work with data available in tables for bulk
addition of nodes, edges, and associated metadata. Use graph selections
and traversals to apply changes to specific nodes or edges. A wide
selection of graph algorithms allow for the analysis of graphs. Visualize
the graphs and take advantage of any aesthetic properties assigned to
nodes and edges.
Description: Build graph/network structures using functions for stepwise
addition and deletion of nodes and edges. Work with data available in
tables for bulk addition of nodes, edges, and associated metadata. Use
graph selections and traversals to apply changes to specific nodes or
edges. A wide selection of graph algorithms allow for the analysis of
graphs. Visualize the graphs and take advantage of any aesthetic
properties assigned to nodes and edges.
License: MIT + file LICENSE
URL: https://rich-iannone.github.io/DiagrammeR/, https://github.com/rich-iannone/DiagrammeR
URL: https://rich-iannone.github.io/DiagrammeR/,
https://github.com/rich-iannone/DiagrammeR
BugReports: https://github.com/rich-iannone/DiagrammeR/issues
Depends:
R (>= 3.2)
Imports:
curl,
dplyr (>= 1.0.7),
downloader (>= 0.4),
glue (>= 1.5.0),
htmltools (>= 0.5.2),
htmlwidgets (>= 1.5),
Expand All @@ -38,13 +38,15 @@ Imports:
viridis (>= 0.6.2),
visNetwork (>= 2.1.0)
Suggests:
covr,
DiagrammeRsvg,
rsvg,
knitr,
testthat,
rmarkdown
rmarkdown,
rsvg,
testthat (>= 3.1.0)
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
13 changes: 13 additions & 0 deletions R/DiagrammeR-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' @keywords internal
#' @aliases DiagrammeR-package
"_PACKAGE"

## usethis namespace: start
#' @import rlang
#' @import htmlwidgets
#' @import RColorBrewer
#' @import glue
#' @importFrom magrittr not
#' @import visNetwork
## usethis namespace: end
NULL
1 change: 0 additions & 1 deletion R/DiagrammeR.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
#' ")
#' }
#'
#' @import htmlwidgets
#' @export
DiagrammeR <- function(
diagram = "",
Expand Down
2 changes: 1 addition & 1 deletion R/add_balanced_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ add_balanced_tree <- function(
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
if (graph_object_valid(graph) == FALSE) {
if (!graph_object_valid(graph)) {

emit_error(
fcn_name = fcn_name,
Expand Down
2 changes: 1 addition & 1 deletion R/add_cycle.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ add_cycle <- function(
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
if (graph_object_valid(graph) == FALSE) {
if (!graph_object_valid(graph)) {

emit_error(
fcn_name = fcn_name,
Expand Down
19 changes: 7 additions & 12 deletions R/add_edge.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
#'
#' @family Edge creation and removal
#'
#' @import rlang
#' @export
add_edge <- function(
graph,
Expand All @@ -123,22 +122,22 @@ add_edge <- function(
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
if (graph_object_valid(graph) == FALSE) {
if (!graph_object_valid(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph object is not valid")
}

# Validation: Graph contains nodes
if (graph_contains_nodes(graph) == FALSE) {
if (!graph_contains_nodes(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph contains no nodes, so, an edge cannot be added")
}

if (length(from) > 1 | length(to) > 1) {
if (length(from) > 1 || length(to) > 1) {

emit_error(
fcn_name = fcn_name,
Expand Down Expand Up @@ -166,13 +165,11 @@ add_edge <- function(

edge_aes_tbl <-
dplyr::as_tibble(edge_aes) %>%
dplyr::select(-index__)
dplyr::select(-"index__")
}

if ("id" %in% colnames(edge_aes_tbl)) {
edge_aes_tbl <-
edge_aes_tbl %>%
dplyr::select(-id)
edge_aes_tbl$id <- NULL
}
}

Expand All @@ -191,16 +188,14 @@ add_edge <- function(
}

if ("id" %in% colnames(edge_data_tbl)) {
edge_data_tbl <-
edge_data_tbl %>%
dplyr::select(-id)
edge_data_tbl$id <- NULL
}
}

# If `from` and `to` values provided as character
# values, assume that these values refer to node
# `label` attr values
if (is.character(from) & is.character(to)) {
if (is.character(from) && is.character(to)) {

# Stop function if the label for
# `from` does not exist in the graph
Expand Down
9 changes: 4 additions & 5 deletions R/add_edge_clone.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ add_edge_clone <- function(
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
if (graph_object_valid(graph) == FALSE) {
if (!graph_object_valid(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph object is not valid")
}

# Validation: Graph contains edges
if (graph_contains_edges(graph) == FALSE) {
if (!graph_contains_edges(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph contains no edges")
}

# Stop function if edge is not a single numerical value
if (length(edge) > 1 | inherits(edge, "character") | inherits(edge, "logical")) {
if (length(edge) > 1 || rlang::inherits_any(edge, c("character", "logical"))) {

emit_error(
fcn_name = fcn_name,
Expand All @@ -117,8 +117,7 @@ add_edge_clone <- function(
# Get the value for the latest `version_id` for
# graph (in the `graph_log`)
current_graph_log_version_id <-
graph$graph_log$version_id %>%
max()
max(graph$graph_log$version_id)

# Get the number of columns in the graph's
# internal edge data frame
Expand Down
4 changes: 2 additions & 2 deletions R/add_edge_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ add_edge_df <- function(
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
if (graph_object_valid(graph) == FALSE) {
if (!graph_object_valid(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph object is not valid")
}

# Validation: Graph contains nodes
if (graph_contains_nodes(graph) == FALSE) {
if (!graph_contains_nodes(graph)) {

emit_error(
fcn_name = fcn_name,
Expand Down
23 changes: 9 additions & 14 deletions R/add_edges_from_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
#'
#' @family Edge creation and removal
#'
#' @import rlang
#' @export
add_edges_from_table <- function(
graph,
Expand All @@ -103,15 +102,15 @@ add_edges_from_table <- function(
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
if (graph_object_valid(graph) == FALSE) {
if (!graph_object_valid(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph object is not valid")
}

# Validation: Graph contains nodes
if (graph_contains_nodes(graph) == FALSE) {
if (!graph_contains_nodes(graph)) {

emit_error(
fcn_name = fcn_name,
Expand Down Expand Up @@ -210,8 +209,8 @@ add_edges_from_table <- function(
dplyr::left_join(
ndf %>% dplyr::select(id, !!from_to_map),
by = stats::setNames(from_to_map, from_col)) %>%
dplyr::select(id) %>%
dplyr::rename(from = id) %>%
dplyr::select("id") %>%
dplyr::rename(from = "id") %>%
dplyr::mutate(from = as.integer(from))

# Get the `to` col
Expand All @@ -221,8 +220,8 @@ add_edges_from_table <- function(
dplyr::left_join(
ndf %>% dplyr::select(id, !!from_to_map),
by = stats::setNames(from_to_map, to_col)) %>%
dplyr::select(id) %>%
dplyr::rename(to = id) %>%
dplyr::select("id") %>%
dplyr::rename(to = "id") %>%
dplyr::mutate(to = as.integer(to))

# Combine the `from` and `to` columns together along
Expand All @@ -236,9 +235,7 @@ add_edges_from_table <- function(
# Add in a `rel` column (filled with NAs) if it's not
# already in the table
if (!("rel" %in% colnames(edf))) {
edf <-
edf %>%
dplyr::mutate(rel = NA_character_)
edf$rel <- NA_character_
}

# Use the `select()` function to arrange the
Expand All @@ -261,10 +258,8 @@ add_edges_from_table <- function(

# Optionally set the `rel` attribute with a single
# value repeated down
if (is.null(rel_col) & !is.null(set_rel)) {
edf <-
edf %>%
dplyr::mutate(rel = as.character(set_rel))
if (is.null(rel_col) && !is.null(set_rel)) {
edf$rel <- as.character(set_rel)
}

# If values for `drop_cols` provided, filter the CSV
Expand Down
6 changes: 3 additions & 3 deletions R/add_edges_w_string.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ add_edges_w_string <- function(
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
if (graph_object_valid(graph) == FALSE) {
if (!graph_object_valid(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph object is not valid")
}

# Validation: Graph contains nodes
if (graph_contains_nodes(graph) == FALSE) {
if (!graph_contains_nodes(graph)) {

emit_error(
fcn_name = fcn_name,
Expand Down Expand Up @@ -123,7 +123,7 @@ add_edges_w_string <- function(

# Split the edge expressions in an undirected
# graph into `from` and `to` vectors
if (graph$directed == FALSE) {
if (!graph$directed) {
from <-
sapply(strsplit(edges_split, "--"), "[[", 1)

Expand Down
10 changes: 5 additions & 5 deletions R/add_forward_edges_ws.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,23 @@ add_forward_edges_ws <- function(
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
if (graph_object_valid(graph) == FALSE) {
if (!graph_object_valid(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph object is not valid")
}

# Validation: Graph contains edges
if (graph_contains_edges(graph) == FALSE) {
if (!graph_contains_edges(graph)) {

emit_error(
fcn_name = fcn_name,
reasons = "The graph contains no edges")
}

# Validation: Graph object has valid edge selection
if (graph_contains_edge_selection(graph) == FALSE) {
if (!graph_contains_edge_selection(graph)) {

emit_error(
fcn_name = fcn_name,
Expand All @@ -102,10 +102,10 @@ add_forward_edges_ws <- function(
# graph's selection
edges_in_selection <-
graph$edge_selection %>%
dplyr::select(from, to)
dplyr::select("from", "to")

# Get the number of edges in the graph
edges_graph_1 <- graph %>% count_edges()
edges_graph_1 <- count_edges(graph)

# Add new edges to the graph for every edge
# in the graph's active selection
Expand Down
Loading

0 comments on commit fd77d85

Please sign in to comment.