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

Switch generate_dot() to use double quotes instead of single quotes #493

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
34 changes: 17 additions & 17 deletions R/generate_dot.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
graph_attrs <-
global_attrs %>%
dplyr::filter(attr_type == "graph") %>%
dplyr::mutate(string = paste0(attr, " = '", value, "'"))
dplyr::mutate(string = paste0(attr, " = \"", value, "\""))

graph_attrs <-
graph_attrs %>%
Expand All @@ -39,7 +39,7 @@
node_attrs <-
global_attrs %>%
dplyr::filter(attr_type == "node") %>%
dplyr::mutate(string = paste0(attr, " = '", value, "'"))
dplyr::mutate(string = paste0(attr, " = \"", value, "\""))

node_attrs <-
node_attrs %>%
Expand Down Expand Up @@ -67,7 +67,7 @@
edge_attrs <-
global_attrs %>%
dplyr::filter(attr_type == "edge") %>%
dplyr::mutate(string = paste0(attr, " = '", value, "'"))
dplyr::mutate(string = paste0(attr, " = \"", value, "\""))

edge_attrs <-
edge_attrs %>%
Expand Down Expand Up @@ -403,7 +403,7 @@
!is.na(nodes_df[i, j]))) {
attribute <-
paste0(colnames(nodes_df)[j],
" = ", "'", nodes_df[i, j], "'")
" = ", "\"", nodes_df[i, j], "\"")
} else if (all(!(colnames(nodes_df)[j] %in%
c("label", "tooltip")),
is.na(nodes_df[i, j]))) {
Expand All @@ -413,7 +413,7 @@
!is.na(nodes_df[i, j]))) {
attribute <-
paste0(colnames(nodes_df)[j],
" = ", "'", nodes_df[i, j], "'")
" = ", "\"", nodes_df[i, j], "\"")
}
attr_string <- c(attr_string, attribute)
}
Expand All @@ -427,17 +427,17 @@
# Generate a line of node objects when an
# attribute string exists
if (exists("attr_string")) {
line <- paste0(" '", nodes_df[i, 1], "'",
line <- paste0(" \"", nodes_df[i, 1], "\"",
" [", attr_string, "] ")
}

# Generate a line of node objects when an
# attribute string doesn't exist
if (!exists("attr_string")) {
line <-
paste0(" '",
paste0(" \"",

Check warning on line 438 in R/generate_dot.R

View check run for this annotation

Codecov / codecov/patch

R/generate_dot.R#L438

Added line #L438 was not covered by tests
nodes_df[i, 1],
"'")
"\"")
}
node_block <- c(node_block, line)
}
Expand Down Expand Up @@ -470,8 +470,8 @@
} else {
cluster_block <-
paste0(
"subgraph cluster", i, "{\nlabel='",
names(clusters)[[i]], "'\n",
"subgraph cluster", i, "{\nlabel=\"",
names(clusters)[[i]], "\"\n",

Check warning on line 474 in R/generate_dot.R

View check run for this annotation

Codecov / codecov/patch

R/generate_dot.R#L473-L474

Added lines #L473 - L474 were not covered by tests
paste0(clusters[[i]], collapse = "\n"), "}\n"
)
}
Expand Down Expand Up @@ -572,8 +572,8 @@
edges_df[i, j] != '')) {
attribute <-
paste0(colnames(edges_df)[j],
" = ", "'", edges_df[i, j],
"'")
" = ", "\"", edges_df[i, j],
"\"")
} else if (all(!(colnames(edges_df)[j] %in%
c("edgetooltip", "headtooltip",
"label", "labeltooltip",
Expand All @@ -590,7 +590,7 @@
edges_df[i, j] != '')) {
attribute <-
paste0(colnames(edges_df)[j],
" = ", "'", edges_df[i, j], "'")
" = ", "\"", edges_df[i, j], "\"")
}
attr_string <- c(attr_string, attribute)
}
Expand All @@ -605,9 +605,9 @@
# attribute string exists
if (exists("attr_string")) {
line <-
paste0("'", edges_df[i, from_column], "'",
paste0("\"", edges_df[i, from_column], "\"",
ifelse(directed, "->", "--"),
"'", edges_df[i, to_column], "'",
"\"", edges_df[i, to_column], "\"",
paste0(" [", attr_string, "] "))
}

Expand All @@ -616,9 +616,9 @@
if (!exists("attr_string")) {
line <-
paste0(" ",
"'", edges_df[i, from_column], "'",
"\"", edges_df[i, from_column], "\"",
ifelse(directed, "->", "--"),
"'", edges_df[i, to_column], "'",
"\"", edges_df[i, to_column], "\"",
" ")
}
edge_block <- c(edge_block, line)
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-generate_dot.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# helper functions
node <- function(id, label = NA) {
if (all(is.na(label))) {
paste0("'", id, "'")
paste0("\"", id, "\"")
} else {
paste0("'", id, "' \\[label = '", label, "'\\]")
paste0("\"", id, "\" \\[label = \"", label, "\"\\]")
}
}
edge <- function(from, to) paste0("'", from, "'->'", to, "'")
attrib_block <- "\\[[[:alnum:]'=.,[:space:]]*\\]"
edge <- function(from, to) paste0("\"", from, "\"->\"", to, "\"")
attrib_block <- "\\[[[:alnum:]\"=.,[:space:]]*\\]"

expect_dot <- function(graph, pattern) {
expect_match(
Expand Down