From d8971b298a3565c995ea9e4f1043e7b268dcffcd Mon Sep 17 00:00:00 2001 From: mpadge Date: Thu, 6 Jun 2024 11:44:23 +0200 Subject: [PATCH 1/3] fix bug in matching points to verts for #229 --- DESCRIPTION | 2 +- R/dists.R | 3 +++ codemeta.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4f05528e..3ede2b30 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dodgr Title: Distances on Directed Graphs -Version: 0.4.0.011 +Version: 0.4.0.012 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")), person("Andreas", "Petutschnig", role = "aut"), diff --git a/R/dists.R b/R/dists.R index ab355292..3b4575aa 100644 --- a/R/dists.R +++ b/R/dists.R @@ -227,6 +227,9 @@ get_index_id_cols <- function (graph, is.matrix (pts) || is.data.frame (pts)) { index <- get_pts_index (graph, gr_cols, vert_map, pts) + if (is.matrix (pts) || is.data.frame (pts)) { + rownames (pts) <- vert_map$vert [index] + } } else { stop ( "routing points are of unknown form; must be either ", diff --git a/codemeta.json b/codemeta.json index d9f4c0e5..83ca2608 100644 --- a/codemeta.json +++ b/codemeta.json @@ -11,7 +11,7 @@ "codeRepository": "https://github.com/UrbanAnalyst/dodgr", "issueTracker": "https://github.com/UrbanAnalyst/dodgr/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.4.0.011", + "version": "0.4.0.012", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From 021664e806b57fbfd21d4429811e26f4ad54bc45 Mon Sep 17 00:00:00 2001 From: mpadge Date: Thu, 6 Jun 2024 11:45:00 +0200 Subject: [PATCH 2/3] allow from/to to be xy coords for #229 --- DESCRIPTION | 2 +- R/flows.R | 34 +++++++++++++++++++++------------- codemeta.json | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3ede2b30..dbba4303 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dodgr Title: Distances on Directed Graphs -Version: 0.4.0.012 +Version: 0.4.0.013 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")), person("Andreas", "Petutschnig", role = "aut"), diff --git a/R/flows.R b/R/flows.R index 6c5cc926..354ee902 100644 --- a/R/flows.R +++ b/R/flows.R @@ -202,19 +202,7 @@ dodgr_flows_aggregate <- function (graph, stop ("flows matrix is not compatible with 'from'/'to' arguments") } if (pairwise) { - if (length (from) != length (to)) { - stop ( - "'from' and 'to' must be the same length ", - "when using 'pairwise = TRUE'.", - call. = FALSE - ) - } - if (nrow (flows) != length (from)) { - stop ( - "'flows' must be the same length as 'from' and 'to'", - call. = FALSE - ) - } + check_pairwise_from_to (from, to, flows) } if (!quiet) { @@ -597,6 +585,26 @@ check_k <- function (k, from) { list (k = k, nk = nk) } +check_pairwise_from_to <- function (from, to, flows) { + + nf <- ifelse (is.vector (from), length (from), nrow (from)) + nt <- ifelse (is.vector (to), length (to), nrow (to)) + + if (nf != nt) { + stop ( + "'from' and 'to' must be the same length or dimensions", + "when using 'pairwise = TRUE'.", + call. = FALSE + ) + } + if (nrow (flows) != nf) { + stop ( + "'flows' must be the same length or dimensions as 'from' and 'to'", + call. = FALSE + ) + } +} + get_random_prefix <- function (prefix = "flow", n = 5) { diff --git a/codemeta.json b/codemeta.json index 83ca2608..28c017f1 100644 --- a/codemeta.json +++ b/codemeta.json @@ -11,7 +11,7 @@ "codeRepository": "https://github.com/UrbanAnalyst/dodgr", "issueTracker": "https://github.com/UrbanAnalyst/dodgr/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.4.0.012", + "version": "0.4.0.013", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From bc7f205cf617207c500e6eb7e27d3c891853a8f5 Mon Sep 17 00:00:00 2001 From: mpadge Date: Thu, 6 Jun 2024 11:53:24 +0200 Subject: [PATCH 3/3] fix bug in 'get_index_id_cols' for #229 --- DESCRIPTION | 2 +- R/dists.R | 3 ++- codemeta.json | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dbba4303..ce3b5829 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dodgr Title: Distances on Directed Graphs -Version: 0.4.0.013 +Version: 0.4.0.014 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")), person("Andreas", "Petutschnig", role = "aut"), diff --git a/R/dists.R b/R/dists.R index 3b4575aa..be0945e7 100644 --- a/R/dists.R +++ b/R/dists.R @@ -227,7 +227,8 @@ get_index_id_cols <- function (graph, is.matrix (pts) || is.data.frame (pts)) { index <- get_pts_index (graph, gr_cols, vert_map, pts) - if (is.matrix (pts) || is.data.frame (pts)) { + if ((is.matrix (pts) || is.data.frame (pts)) && + !any (duplicated (index))) { rownames (pts) <- vert_map$vert [index] } } else { diff --git a/codemeta.json b/codemeta.json index 28c017f1..5957c9ff 100644 --- a/codemeta.json +++ b/codemeta.json @@ -11,7 +11,7 @@ "codeRepository": "https://github.com/UrbanAnalyst/dodgr", "issueTracker": "https://github.com/UrbanAnalyst/dodgr/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.4.0.013", + "version": "0.4.0.014", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R",