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

Fix pkgdown config and move curl to Suggests #505

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 1 addition & 3 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
75 changes: 33 additions & 42 deletions R/import_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
length(unlist(strsplit(graph_file, "/")))]

# Download the file
rlang::check_installed("curl", "to download a graph file.")

Check warning on line 89 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L89

Added line #L89 was not covered by tests
curl::curl_download(graph_file, destfile = dest_file)

# Extract the file and get the filename of the extracted file
Expand All @@ -109,19 +110,10 @@
file_extension <- gsub(".*\\.([a-zA-Z]*?)", "\\1", graph_file)

# Determine file type from file extension
if (file_extension == "gml") {
file_type <- "gml"
} else if (file_extension == "sif") {
file_type <- "sif"
} else if (file_extension == "edges") {
file_type <- "edges"
} else if (file_extension == "mtx") {
file_type <- "mtx"
} else {
rlang::arg_match0(file_extension, c("gml", "sif", "edges", "mtx"))

Check warning on line 113 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L113

Added line #L113 was not covered by tests

cli::cli_abort(
"The file type is not known so it can't be imported.")
}
# one of gml, sif, edges, or mtx
file_type <- file_extension

Check warning on line 116 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L116

Added line #L116 was not covered by tests
}

if (file_type == "edges") {
Expand All @@ -133,7 +125,7 @@
first_line <- grep("^[^%].*", edges_document)[1]

# Determine the number of lines to skip
lines_to_skip <- first_line - 1
lines_to_skip <- first_line - 1L

Check warning on line 128 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L128

Added line #L128 was not covered by tests

# Set default attribute names and column types
# for an `edges` file
Expand Down Expand Up @@ -162,29 +154,28 @@

edges <-
edges %>%
dplyr::mutate(id = seq_len(n_rows)) %>%
dplyr::mutate(rel = NA_character_) %>%
dplyr::mutate(
id = seq_len(n_rows),
rel = NA_character_

Check warning on line 159 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L157-L159

Added lines #L157 - L159 were not covered by tests
) %>%
dplyr::relocate("id", "from", "to", "rel") %>%
as.data.frame(stringsAsFactors = FALSE)

# Create a node data frame
# taking edges$from and edges$to
edge_id_from <- as.integer(edges$from)
edge_id_to <- as.integer(edges$to)

Check warning on line 167 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L166-L167

Added lines #L166 - L167 were not covered by tests

nodes_raw <- unique(c(edge_id_from, edge_id_to))

Check warning on line 169 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L169

Added line #L169 was not covered by tests

nodes <-
dplyr::bind_rows(
dplyr::tibble(
id = edges %>%
dplyr::as_tibble() %>%
dplyr::select("from") %>%
purrr::flatten_int()),
dplyr::tibble(
id = edges %>%
dplyr::as_tibble() %>%
dplyr::select("to") %>%
purrr::flatten_int())) %>%
dplyr::distinct() %>%
dplyr::arrange(id) %>%
dplyr::mutate(type = NA_character_,
label = as.character(id)) %>%
as.data.frame(stringsAsFactors = FALSE)
data.frame(
id = nodes_raw,
type = NA_character_,
label = as.character(nodes_raw),
stringsAsFactors = FALSE

Check warning on line 176 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L172-L176

Added lines #L172 - L176 were not covered by tests
)
nodes <- dplyr::arrange(nodes, .data$id)

Check warning on line 178 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L178

Added line #L178 was not covered by tests

# Create the graph
the_graph <-
Expand Down Expand Up @@ -259,10 +250,10 @@
# Extract information on whether graph is directed
graph_directed <-
unlist(
stringr::str_replace_all(
stringr::str_remove_all(

Check warning on line 253 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L253

Added line #L253 was not covered by tests
stringr::str_extract_all(gml_document,
"directed [0-1]"),
"directed ", ""))
"directed "))

Check warning on line 256 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L256

Added line #L256 was not covered by tests

# Extract all node definitions
node_defs <-
Expand All @@ -273,11 +264,11 @@
# Get all node ID values
node_id <-
as.integer(
stringr::str_replace_all(
stringr::str_remove_all(

Check warning on line 267 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L267

Added line #L267 was not covered by tests
stringr::str_extract_all(
node_defs,
"id [a-z0-9_]*"),
"id ", ""))
"id "))

Check warning on line 271 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L271

Added line #L271 was not covered by tests

# Get all node label values, if they exist
if (any(stringr::str_detect(node_defs, "label"))) {
Expand All @@ -299,19 +290,19 @@

edges_from <-
as.integer(
stringr::str_replace_all(
stringr::str_remove_all(

Check warning on line 293 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L293

Added line #L293 was not covered by tests
stringr::str_extract_all(
edge_defs,
"source [a-z0-9_]*"),
"source ", ""))
"source "))

Check warning on line 297 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L297

Added line #L297 was not covered by tests

edges_to <-
as.integer(
stringr::str_replace_all(
stringr::str_remove_all(

Check warning on line 301 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L301

Added line #L301 was not covered by tests
stringr::str_extract_all(
edge_defs,
"target [a-z0-9_]*"),
"target ", ""))
"target "))

Check warning on line 305 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L305

Added line #L305 was not covered by tests


if (any(stringr::str_detect(edge_defs, "label"))) {
Expand All @@ -336,11 +327,11 @@

# Create all nodes for graph
all_nodes <-
dplyr::tibble(
data.frame(

Check warning on line 330 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L330

Added line #L330 was not covered by tests
id = node_id,
type = NA_character_,
label = NA_character_) %>%
as.data.frame(stringsAsFactors = FALSE)
label = NA_character_,
stringsAsFactors = FALSE)

Check warning on line 334 in R/import_graph.R

View check run for this annotation

Codecov / codecov/patch

R/import_graph.R#L333-L334

Added lines #L333 - L334 were not covered by tests

if (exists("node_label")) {
all_nodes$label <- node_label
Expand Down
7 changes: 2 additions & 5 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
destination: docs

home:
strip_header: true

url: https://rich-iannone.github.io/DiagrammeR/

template:
bootstrap: 5

Expand Down Expand Up @@ -347,6 +347,3 @@ reference:
- edge_list_2
- currencies
- usd_exchange_rates

development:
version_tooltip: "Development version"
4 changes: 1 addition & 3 deletions man/DiagrammeR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.