Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cli::cli_abort() everywhere. #502

Merged
merged 15 commits into from
Nov 8, 2023
Merged
2 changes: 2 additions & 0 deletions DiagrammeR.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ PackageCheckArgs: --as-cran --no-manual
PackageRoxygenize: rd,collate,namespace

UseNativePipeOperator: No

SpellingDictionary: en_US
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# DiagrammeR (development version)

* DiagrammeR nows uses testthat 3rd edition (@olivroy, #498)

* No longer use deprecated features from igraph and tidyselect (>= 1.2.0) (@olivroy, #497)

* Error messages have been reviewed and now use cli (@olivroy, #499, #502)

* It is now easier to install suggested packages on the fly. DiagrammeR now uses `rlang::check_installed()` internally. (@olivroy, #499)

# DiagrammeR 1.0.10

* Remove dependency on the **influenceR** package, which also means removing the `get_constraint()` and `get_bridging()` graph inspection functions.
Expand Down Expand Up @@ -138,7 +146,7 @@

* Degree data for plots can now be easily obtained using the `get_degree_distribution()` and `get_degree_histogram()` functions

* Global graph attributes are now more easily modifiable using a set of functions for this purpose: `add_global_graph_attrs()`, `clear_global_graph_attrs()`, `delete_global_graph_attrs()`, `get_global_graph_attrs()`, `set_global_graph_attrs()`
* Global graph attributes are now more easily modifiable using a set of functions for this purpose: `add_global_graph_attrs()`, `delete_global_graph_attrs()`, `get_global_graph_attr_info()`.

* Added option to display different text labels on nodes via the `display` node attribute; this is easily set with the `set_node_attr_to_display()` function

Expand Down
2 changes: 1 addition & 1 deletion R/DiagrammeR.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @description
#'
#' Make diagrams in R using \href{https://github.com/mdaines/viz.js}{viz.js} or
#' Make diagrams in R using \href{https://github.com/mdaines/viz-js}{viz.js} or
#' \href{https://github.com/mermaid-js/mermaid}{mermaid.js} with infrastructure
#' provided by \href{http://www.htmlwidgets.org/}{htmlwidgets}.
#'
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 @@ -290,7 +290,7 @@ add_balanced_tree <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_cycle.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ add_cycle <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
4 changes: 2 additions & 2 deletions R/add_edge.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ add_edge <- function(

# Iteratively set edge attribute values for
# the new edge in the graph
for (i in 1:ncol(edge_aes_tbl)) {
for (i in seq_len(ncol(edge_aes_tbl))) {
graph <-
graph %>%
set_edge_attrs_ws(
Expand Down Expand Up @@ -318,7 +318,7 @@ add_edge <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
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 @@ -91,7 +91,7 @@
# to an edge in the graph
if (!(edge %in% graph$edges_df$id)) {

abort(
cli::cli_abort(

Check warning on line 94 in R/add_edge_clone.R

View check run for this annotation

Codecov / codecov/patch

R/add_edge_clone.R#L94

Added line #L94 was not covered by tests
"The value provided in `edge` does not correspond to an edge in the graph.")
}

Expand Down Expand Up @@ -125,12 +125,11 @@
# Create an edge selection for the
# new edge in the graph
graph <-
graph %>%
select_last_edges_created()
select_last_edges_created(graph)

# Iteratively set edge attribute values for
# the new edges in the graph
for (i in 1:ncol(edge_attr_vals)) {
for (i in seq_len(ncol(edge_attr_vals))) {

graph$edges_df[
nrow(graph$edges_df),
Expand All @@ -155,7 +154,7 @@
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
7 changes: 3 additions & 4 deletions R/add_edge_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
check_graph_valid(graph)

# Validation: Graph contains nodes
check_graph_contains_nodes(graph,extra_msg = " so, edges cannot be added")
check_graph_contains_nodes(graph,extra_msg = "So, edges cannot be added.")

# Get the number of edges ever created for
# this graph
Expand Down Expand Up @@ -92,7 +92,7 @@
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand All @@ -103,8 +103,7 @@
# Perform graph actions, if any are available
if (nrow(graph$graph_actions) > 0) {
graph <-
graph %>%
trigger_graph_actions()
trigger_graph_actions(graph)

Check warning on line 106 in R/add_edge_df.R

View check run for this annotation

Codecov / codecov/patch

R/add_edge_df.R#L106

Added line #L106 was not covered by tests
}

# Write graph backup if the option is set
Expand Down
2 changes: 1 addition & 1 deletion R/add_edges_from_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ add_edges_from_table <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_edges_w_string.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ add_edges_w_string <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
11 changes: 5 additions & 6 deletions R/add_forward_edges_ws.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@
# Get the time of function start
time_function_start <- Sys.time()

# Get the name of the function
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
check_graph_valid(graph)

Expand Down Expand Up @@ -114,11 +111,14 @@
# the graph
edges_added <- edges_graph_2 - edges_graph_1

# Get the name of the function
fcn_name <- get_calling_fcn()

# Update the `graph_log` df with an action
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand All @@ -129,8 +129,7 @@
# Perform graph actions, if any are available
if (nrow(graph$graph_actions) > 0) {
graph <-
graph %>%
trigger_graph_actions()
trigger_graph_actions(graph)

Check warning on line 132 in R/add_forward_edges_ws.R

View check run for this annotation

Codecov / codecov/patch

R/add_forward_edges_ws.R#L132

Added line #L132 was not covered by tests
}

# Write graph backup if the option is set
Expand Down
4 changes: 2 additions & 2 deletions R/add_full_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ add_full_graph <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down Expand Up @@ -452,7 +452,7 @@ add_full_graph <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_global_graph_attrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ add_global_graph_attrs <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_gnm_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ add_gnm_graph <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_gnp_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ add_gnp_graph <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
8 changes: 4 additions & 4 deletions R/add_graph_action.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ add_graph_action <- function(
# Create a character expression for the
# function to evaluate at every graph
# transformation step
if (length(fcn_args) == 0) {
if (length(fcn_args) == 0L) {
char_expr <-
paste0(
fcn,
Expand Down Expand Up @@ -111,8 +111,8 @@ add_graph_action <- function(
# Create a data frame row with the new graph action
new_graph_action <-
data.frame(
action_index = ifelse(nrow(graph$graph_actions) == 0, 1,
max(graph$graph_actions$action_index) + 1),
action_index = ifelse(nrow(graph$graph_actions) == 0L, 1L,
max(graph$graph_actions$action_index) + 1L),
action_name = action_name %||% NA_character_,
expression = char_expr,
stringsAsFactors = FALSE)
Expand All @@ -128,7 +128,7 @@ add_graph_action <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_grid_2d.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ add_grid_2d <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
10 changes: 3 additions & 7 deletions R/add_grid_3d.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ add_grid_3d <- function(
# Create an edge data frame for the grid graph
grid_edges <-
create_edge_df(
from = grid %>%
get_edge_df() %>%
dplyr::pull(from),
to = grid %>%
get_edge_df() %>%
dplyr::pull(to),
from = get_edge_df(grid)$from,
to = get_edge_df(grid)$to,
rel = rel)

# Create the grid graph
Expand Down Expand Up @@ -273,7 +269,7 @@ add_grid_3d <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_growing_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ add_growing_graph <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_islands_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ add_islands_graph <- function(
graph_log <-
add_action_to_log(
graph_log = graph_log,
version_id = nrow(graph_log) + 1,
version_id = nrow(graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_n_node_clones.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ add_n_node_clones <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_n_nodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ add_n_nodes <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
5 changes: 1 addition & 4 deletions R/add_n_nodes_ws.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ add_n_nodes_ws <- function(
# Get the time of function start
time_function_start <- Sys.time()

# Get the name of the function
fcn_name <- get_calling_fcn()

# Validation: Graph object is valid
check_graph_valid(graph)

Expand Down Expand Up @@ -393,7 +390,7 @@ add_n_nodes_ws <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
8 changes: 4 additions & 4 deletions R/add_node.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ add_node <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down Expand Up @@ -303,7 +303,7 @@ add_node <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down Expand Up @@ -441,7 +441,7 @@ add_node <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down Expand Up @@ -595,7 +595,7 @@ add_node <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
2 changes: 1 addition & 1 deletion R/add_node_clones_ws.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ add_node_clones_ws <- function(
graph$graph_log <-
add_action_to_log(
graph_log = graph$graph_log,
version_id = nrow(graph$graph_log) + 1,
version_id = nrow(graph$graph_log) + 1L,
function_used = fcn_name,
time_modified = time_function_start,
duration = graph_function_duration(time_function_start),
Expand Down
Loading