Skip to content

Commit

Permalink
return list of matrices from dists_proportional for #144
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Sep 12, 2021
1 parent 76fcbf7 commit d4c606e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
17 changes: 13 additions & 4 deletions R/dists-proportional.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#' graph which must have a column named "edge_type" with integer types along
#' which proportional distances are to be aggregated. The value of "edge_type" =
#' 0 is the default type for which proportional distances are not aggregated.
#' @return An expanded distance matrix with number of rows equal to number of
#' "from" points, and number of columns equal to number of "to" points
#' \emph{times} the number of distinct edge types.
#' @return A list of distance matrices of equal dimensions (length(from),
#' length(to)), the first of which ("distance") holds the final distances, while
#' the rest are one matrix for each unique value of "edge_type", holding the
#' distances traversed along those types of edges only.
#' @export
dodgr_dists_proportional <- function (graph,
from = NULL,
Expand All @@ -23,6 +24,7 @@ dodgr_dists_proportional <- function (graph,
stop ("'edge_type' must contain non-negative values only")

edge_type <- graph$edge_type
et <- sort (unique (edge_type))

graph <- tbl_to_df (graph)

Expand Down Expand Up @@ -62,5 +64,12 @@ dodgr_dists_proportional <- function (graph,
to_index$index,
heap)

return (d)
n <-length (to)
d0 <- list ("distances" = d [, seq (n)])
d <- lapply (et, function (i) {
index <- i * n + seq (n) - 1
d [, index] })
names (d) <- et

return (c (d0, d))
}
9 changes: 5 additions & 4 deletions man/dodgr_dists_proportional.Rd

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

0 comments on commit d4c606e

Please sign in to comment.