Skip to content

Commit

Permalink
Merge branch 'main' into length-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy authored Nov 16, 2023
2 parents cefe768 + 5ad71cb commit ad17a9c
Show file tree
Hide file tree
Showing 134 changed files with 1,515 additions and 1,500 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ BugReports: https://github.com/rich-iannone/DiagrammeR/issues
Depends:
R (>= 3.2)
Imports:
curl,
dplyr (>= 1.0.7),
glue (>= 1.5.0),
htmltools (>= 0.5.2),
Expand All @@ -41,6 +40,7 @@ Imports:
viridis (>= 0.6.2),
visNetwork (>= 2.1.0)
Suggests:
curl,
DiagrammeRsvg,
knitr,
rmarkdown,
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

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

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

* 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)

* Some conditions were corrected in `trav_in_until()` and `trav_out_until()` (@olivroy, #504)

* `DiagrammeR()` checks the `type` argument more strictly. (@olivroy, #506)

# 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
10 changes: 4 additions & 6 deletions R/DiagrammeR.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#' )
#'
#' # Load in the 'mtcars' dataset
#' data(mtcars)
#' mtcars
#' connections <- sapply(
#' 1:ncol(mtcars)
#' ,function(i) {
Expand Down Expand Up @@ -102,8 +102,6 @@
#' # http://www.cs.uku.fi/research/publications/reports/A-2003-1/page91.pdf
#' # draw some sequence diagrams with DiagrammeR
#'
#' library(DiagrammeR)
#'
#' DiagrammeR("
#' sequenceDiagram;
#' customer->>ticket seller: ask for ticket;
Expand Down Expand Up @@ -131,10 +129,10 @@ DiagrammeR <- function(
# DiagrammeR will serve as a wrapper function for mermaid and grVis
if (grepl(x = type, pattern = "[m,M](erm).*")) {

mermaid(diagram, ... )
mermaid(diagram, ...)

} else if (grepl(x = type, pattern = "[g,G]?[r,R]?.*[v,V][i].*" )) {
grViz(diagram, ... )
} else if (grepl(x = type, pattern = "[g,G]?[r,R]?.*[v,V][i].*")) {
grViz(diagram, ...)

} else {
abort("The type should be `mermaid` or `grViz`.")
Expand Down
9 changes: 5 additions & 4 deletions R/add_balanced_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ add_balanced_tree <- function(
rep(seq(nodes[1],
nodes[length(
seq(nodes[2],
nodes[length(nodes)]))/k]), k)),
nodes[length(nodes)])) / k]),
k)),
to = seq(nodes[2], nodes[length(nodes)]),
rel = rel)

Expand Down Expand Up @@ -271,10 +272,10 @@ add_balanced_tree <- function(

# If the input graph is not empty, combine graphs
# using the `combine_graphs()` function
if (!is_graph_empty(graph)) {
graph <- combine_graphs(graph, tree_graph)
} else {
if (is_graph_empty(graph)) {
graph <- tree_graph
} else {
graph <- combine_graphs(graph, tree_graph)
}

# Update the `last_node` counter
Expand Down
6 changes: 3 additions & 3 deletions R/add_cycle.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ add_cycle <- function(

# If the input graph is not empty, combine graphs
# using the `combine_graphs()` function
if (!is_graph_empty(graph)) {
graph <- combine_graphs(graph, cycle_graph)
} else {
if (is_graph_empty(graph)) {
graph <- cycle_graph
} else {
graph <- combine_graphs(graph, cycle_graph)
}

# Update the `last_node` counter
Expand Down
2 changes: 1 addition & 1 deletion R/add_edge_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ add_edge_df <- function(
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
10 changes: 4 additions & 6 deletions R/add_edges_from_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,10 @@ add_edges_from_table <- function(

# Optionally set the `rel` attribute from a
# specified column in the CSV
if (!is.null(rel_col)) {
if (!is.null(rel_col) && any(colnames(csv) == rel_col)) {

if (any(colnames(csv) == rel_col)) {
colnames(csv)[which(colnames(csv) == rel_col)] <- "rel"
csv$rel <- as.character(csv$rel)
}
colnames(csv)[which(colnames(csv) == rel_col)] <- "rel"
csv$rel <- as.character(csv$rel)
}

# Extract the ndf from the graph
Expand Down Expand Up @@ -231,7 +229,7 @@ add_edges_from_table <- function(
# Add in an `id` column
edf <-
dplyr::bind_cols(
data.frame(id = as.integer(1:nrow(edf)) + graph$last_edge),
data.frame(id = seq_len(nrow(edf)) + as.integer(graph$last_edge)),
edf)

# Optionally set the `rel` attribute with a single
Expand Down
55 changes: 26 additions & 29 deletions R/add_full_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
#' label = TRUE,
#' rel = "related_to",
#' edge_wt_matrix = edge_wt_matrix,
#' keep_loops = FALSE)
#' keep_loops = FALSE
#' )
#'
#' # Show the graph's node
#' # data frame (ndf)
Expand Down Expand Up @@ -198,7 +199,9 @@ add_full_graph <- function(
new_graph,
edge_attr = "weight",
values = as.numeric(edge_wt_matrix)[
which(as.numeric(adj_matrix) == 1)])
which(as.numeric(adj_matrix) == 1)
]
)
}
}

Expand All @@ -221,8 +224,8 @@ add_full_graph <- function(
values = edge_wt_matrix[
lower.tri(
edge_wt_matrix,
diag = ifelse(!keep_loops,
FALSE, TRUE))])
diag = keep_loops # TRUE or FALSE
)])
}
}

Expand All @@ -236,39 +239,33 @@ add_full_graph <- function(
}
}

if (length(label) > 1) {
if (length(label) == n) {
new_graph$nodes_df[, 3] <- label
}
if (n > 1 && length(label) == n) {
new_graph$nodes_df[, 3] <- label
}

if (length(label) == 1) {
if (label) {
if (!is.null(edge_wt_matrix)) {

if (!is.null(colnames(edge_wt_matrix))) {
ewm_names <- colnames(edge_wt_matrix)
}
if (!is.null(rownames(edge_wt_matrix))) {
ewm_names <- rownames(edge_wt_matrix)
}

if (length(ewm_names) == n) {
new_graph$nodes_df[, 3] <- ewm_names
}
}
if (isTRUE(label) && !is.null(edge_wt_matrix)) {

if (!is.null(colnames(edge_wt_matrix))) {
ewm_names <- colnames(edge_wt_matrix)
}

if (!is.null(rownames(edge_wt_matrix))) {
ewm_names <- rownames(edge_wt_matrix)
}

if (length(ewm_names) == n) {
new_graph$nodes_df[, 3] <- ewm_names
}
}

# Add `type` values to all new nodes
if (!is.null(type) &&
length(type) == 1) {
if (length(type) == 1) {
new_graph$nodes_df[, 2] <- type
}

# Add `rel` values to all new edges
if (!is.null(rel) &&
length(rel) == 1) {
# NULL is length 0
if (length(rel) == 1) {
new_graph$edges_df[, 4] <- rel
}

Expand All @@ -279,7 +276,7 @@ add_full_graph <- function(

if (nrow(node_aes_tbl) < nrow(new_graph$nodes_df)) {

node_aes$index__ <- 1:nrow(new_graph$nodes_df)
node_aes$index__ <- seq_len(nrow(new_graph$nodes_df))

node_aes_tbl <-
dplyr::as_tibble(node_aes) %>%
Expand All @@ -298,7 +295,7 @@ add_full_graph <- function(

if (nrow(node_data_tbl) < nrow(new_graph$nodes_df)) {

node_data$index__ <- 1:nrow(new_graph$nodes_df)
node_data$index__ <- seq_len(nrow(new_graph$nodes_df))

node_data_tbl <-
dplyr::as_tibble(node_data) %>%
Expand Down
14 changes: 6 additions & 8 deletions R/add_global_graph_attrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,18 @@ add_global_graph_attrs <- function(

# Coerce any logical value for `value` to a
# lowercase character value
if (length(value) == 1) {
if (inherits(value, "logical") &&
value %in% c(TRUE, FALSE)) {
value <- tolower(as.character(value))
}
# If value is a single true or false
if (rlang::is_bool(value)) {
value <- tolower(as.character(value))
}

# Create a table for the attributes
global_attrs_to_add <-
dplyr::tibble(
data.frame(
attr = as.character(attr),
value = as.character(value),
attr_type = as.character(attr_type)) %>%
as.data.frame(stringsAsFactors = FALSE)
attr_type = as.character(attr_type),
stringsAsFactors = FALSE)

# Get the global graph attributes already set
# in the graph object
Expand Down
16 changes: 8 additions & 8 deletions R/add_gnm_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ add_gnm_graph <- function(

if (nrow(node_aes_tbl) < nrow(sample_gnm_graph$nodes_df)) {

node_aes$index__ <- 1:nrow(sample_gnm_graph$nodes_df)
node_aes$index__ <- seq_len(nrow(sample_gnm_graph$nodes_df))

node_aes_tbl <-
dplyr::as_tibble(node_aes) %>%
Expand All @@ -150,7 +150,7 @@ add_gnm_graph <- function(

if (nrow(node_data_tbl) < nrow(sample_gnm_graph$nodes_df)) {

node_data$index__ <- 1:nrow(sample_gnm_graph$nodes_df)
node_data$index__ <- seq_len(nrow(sample_gnm_graph$nodes_df))

node_data_tbl <-
dplyr::as_tibble(node_data) %>%
Expand All @@ -169,11 +169,11 @@ add_gnm_graph <- function(

if (nrow(edge_aes_tbl) < nrow(sample_gnm_graph$edges_df)) {

edge_aes$index__ <- 1:nrow(sample_gnm_graph$edges_df)
edge_aes$index__ <- seq_len(nrow(sample_gnm_graph$edges_df))

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

if ("id" %in% colnames(edge_aes_tbl)) {
Expand All @@ -188,7 +188,7 @@ add_gnm_graph <- function(

if (nrow(edge_data_tbl) < nrow(sample_gnm_graph$edges_df)) {

edge_data$index__ <- 1:nrow(sample_gnm_graph$edges_df)
edge_data$index__ <- seq_len(nrow(sample_gnm_graph$edges_df))

edge_data_tbl <-
dplyr::as_tibble(edge_data) %>%
Expand Down Expand Up @@ -234,10 +234,10 @@ add_gnm_graph <- function(

# If the input graph is not empty, combine graphs
# using the `combine_graphs()` function
if (!is_graph_empty(graph)) {
graph <- combine_graphs(graph, sample_gnm_graph)
} else {
if (is_graph_empty(graph)) {
graph <- sample_gnm_graph
} else {
graph <- combine_graphs(graph, sample_gnm_graph)
}

# Update the `last_node` counter
Expand Down
10 changes: 5 additions & 5 deletions R/add_gnp_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ add_gnp_graph <- function(

if (nrow(node_aes_tbl) < nrow(sample_gnp_graph$nodes_df)) {

node_aes$index__ <- 1:nrow(sample_gnp_graph$nodes_df)
node_aes$index__ <- seq_len(nrow(sample_gnp_graph$nodes_df))

node_aes_tbl <-
dplyr::as_tibble(node_aes) %>%
Expand Down Expand Up @@ -185,7 +185,7 @@ add_gnp_graph <- function(

if (nrow(edge_data_tbl) < nrow(sample_gnp_graph$edges_df)) {

edge_data$index__ <- 1:nrow(sample_gnp_graph$edges_df)
edge_data$index__ <- seq_len(nrow(sample_gnp_graph$edges_df))

edge_data_tbl <-
dplyr::as_tibble(edge_data) %>%
Expand Down Expand Up @@ -231,10 +231,10 @@ add_gnp_graph <- function(

# If the input graph is not empty, combine graphs
# using the `combine_graphs()` function
if (!is_graph_empty(graph)) {
graph <- combine_graphs(graph, sample_gnp_graph)
} else {
if (is_graph_empty(graph)) {
graph <- sample_gnp_graph
} else {
graph <- combine_graphs(graph, sample_gnp_graph)
}

# Update the `last_node` counter
Expand Down
6 changes: 3 additions & 3 deletions R/add_grid_2d.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ add_grid_2d <- function(

# If the input graph is not empty, combine graphs
# using the `combine_graphs()` function
if (!is_graph_empty(graph)) {
graph <- combine_graphs(graph, grid_graph)
} else {
if (is_graph_empty(graph)) {
graph <- grid_graph
} else {
graph <- combine_graphs(graph, grid_graph)
}

# Update the `last_node` counter
Expand Down
6 changes: 3 additions & 3 deletions R/add_grid_3d.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ add_grid_3d <- function(

# If the input graph is not empty, combine graphs
# using the `combine_graphs()` function
if (!is_graph_empty(graph)) {
graph <- combine_graphs(graph, grid_graph)
} else {
if (is_graph_empty(graph)) {
graph <- grid_graph
} else {
graph <- combine_graphs(graph, grid_graph)
}

# Update the `last_node` counter
Expand Down
Loading

0 comments on commit ad17a9c

Please sign in to comment.