Skip to content

Commit

Permalink
Add a print method for gPath objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dramanica committed Mar 26, 2024
1 parent b20a5e1 commit b8664de
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(plot,gPath)
S3method(print,gPath)
export("%>%")
export(.gData.valid)
export(.gGraph.valid)
Expand Down
20 changes: 19 additions & 1 deletion R/dijkstra.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ setMethod("dijkstraFrom", "gData", function(x, start) {
## res$xy <- getCoords(x)[allNodes,]
attr(res, "xy") <- coords[allNodes, ]
class(res) <- "gPath"

return(res)
}) # end dijkstraFrom for gData

Expand Down Expand Up @@ -443,3 +442,22 @@ gPath2dist <- function(m, diag = FALSE, upper = FALSE, res.type = c("dist", "vec

return(res)
} # end gPath2dist



###########################################
#' @export

print.gPath <- function(x, ...){
if (length(list(...))){
stop ("additional parameters were passed through ... when none should be given")
}
## printing
cat("\n=== gPath object ===\n")
cat("\n number of paths:", length(x), "\n")
cat("\n available paths (id_origin:id_destination: ")
print(c(utils::head(names(x)),"...\n"))
cat("each path, accessible with [[]] has elements 'length', 'path_detail' and 'length_detail\n")
cat("x and y coordinates of all nodes are stored as an attribute 'xy'")
cat("see ?gPath for details")
}

0 comments on commit b8664de

Please sign in to comment.