From 86488765f111e613e46345fbf2110348df960439 Mon Sep 17 00:00:00 2001 From: Liuxi Mei <liume102@student.liu.se> Date: Tue, 24 Sep 2024 13:45:51 +0200 Subject: [PATCH] UPDATE --- DESCRIPTION | 4 ++-- R/lab_3_submission.R | 5 +++++ R/wiki_graph.R | 2 +- man/update_detail_path.Rd | 4 ++++ man/wiki_graph.Rd | 22 ++++++++++++++++++++++ tests/testthat.R | 4 ++-- 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 man/wiki_graph.Rd diff --git a/DESCRIPTION b/DESCRIPTION index d9a91b8..a3bf7bf 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 a22ac25..8af145a 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 f510d30..d480674 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 4e1e856..b7013cc 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 0000000..23c0a34 --- /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 c3aa518..c9c310c 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") -- GitLab