diff --git a/DESCRIPTION b/DESCRIPTION index d9a91b821f13b83cd645e990eddef9e085a159fe..a3bf7bf8590d0e8b7e4692c2bfc8a878e1682f51 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ -Package: Advanced_R_Group_Cooperation +Package: Cooperation Type: Package -Title: Lab 3 exercise +Title: Advanced R Group Cooperation Version: 1.0 Date: 2024-09-12 Author: Liuxi Mei diff --git a/R/lab_3_submission.R b/R/lab_3_submission.R index a22ac2530062dfc283c34d1f97899df839a085ff..8af145a27e53d641d3d527a0b96283a0516d6d2a 100644 --- a/R/lab_3_submission.R +++ b/R/lab_3_submission.R @@ -7,6 +7,8 @@ #' @param y second number euclidean <- function(x,y) { + x <- abs(x) + y <- abs(y) if (!is.numeric(x) | length(x) != 1){ stop('pls check your input x') } @@ -38,6 +40,9 @@ init_node_distance_list <- function (init_node, graph) { node_distance_list <- list(init_node = 0) # first, get all unqiue nodes all_nodes <- unique(append(graph[,'v1'],graph[,'v2'])) + if (!init_node %in% all_nodes) { + stop('node is not in graph') + } detail_frame <- data.frame(matrix(ncol=length(all_nodes),nrow = 3)) names(detail_frame) <- all_nodes row.names(detail_frame) <- c('is_best_node','node_distance','previous_node') diff --git a/R/wiki_graph.R b/R/wiki_graph.R index f510d303d09849090bac87bdaeb87753f33c3b79..d480674eade0fe0389e6e04556cf74b99f6450db 100644 --- a/R/wiki_graph.R +++ b/R/wiki_graph.R @@ -7,4 +7,4 @@ #' \item{w}{the weight between node v1 and node v2} #' ... #' } -wiki_graph \ No newline at end of file +"wiki_graph" \ No newline at end of file diff --git a/man/update_detail_path.Rd b/man/update_detail_path.Rd index 4e1e856e14f07a222f172046518837b663c91a52..b7013cc4139d3e0454e5b3906a1b68194e75a90b 100644 --- a/man/update_detail_path.Rd +++ b/man/update_detail_path.Rd @@ -18,6 +18,10 @@ update_detail_path( \item{init_node}{the start node in the algorithm} +\item{detail_frame}{to store the shorest path , if it is the best node and the related distance} + +\item{graph}{the graph indicates the relationship of different nodes} + \item{checked_nodes}{the nodes that having found the shortest path} \item{unchecked_nodes}{the nodes that having not found the shortest path} diff --git a/man/wiki_graph.Rd b/man/wiki_graph.Rd new file mode 100644 index 0000000000000000000000000000000000000000..23c0a343b4384d33105f36c6ef9ff27f1bf8db12 --- /dev/null +++ b/man/wiki_graph.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/wiki_graph.R +\docType{data} +\name{wiki_graph} +\alias{wiki_graph} +\title{graph} +\format{ +A data frame with 18 rows and 3 columns: +\describe{ + \item{v1}{node name} + \item{v2}{node name} + \item{w}{the weight between node v1 and node v2} + ... +} +} +\usage{ +wiki_graph +} +\description{ +graph +} +\keyword{datasets} diff --git a/tests/testthat.R b/tests/testthat.R index c3aa5188bc93dfddf3114ad0901d006c2256315a..c9c310c97d87e34f3d736abcd3b57bfd76dff5d6 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -7,6 +7,6 @@ # * https://testthat.r-lib.org/articles/special-files.html library(testthat) -library(Advanced_R_Group_Cooperation) +library(Cooperation) -test_check("Advanced_R_Group_Cooperation") +test_check("Cooperation")