From b8664def40aecbc0f2002cbe151d90b3609a2214 Mon Sep 17 00:00:00 2001 From: Andrea Manica Date: Tue, 26 Mar 2024 13:57:12 +0000 Subject: [PATCH] Add a print method for gPath objects --- NAMESPACE | 1 + R/dijkstra.R | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 8c63a52..4caee1e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/dijkstra.R b/R/dijkstra.R index 8eac55c..661e4fa 100644 --- a/R/dijkstra.R +++ b/R/dijkstra.R @@ -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 @@ -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") +}