From b1a408458870807e39af4ee8e0c59699a8dcb11c Mon Sep 17 00:00:00 2001 From: Amulya Shastry Date: Tue, 24 May 2022 10:57:36 -0400 Subject: [PATCH 1/2] "Added new example_dataset and used it in the example for the euclideanDist function" --- R/data.R | 11 +++++++++++ data-raw/example_data.R | 6 ++++++ man/example_data.Rd | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 R/data.R create mode 100644 data-raw/example_data.R create mode 100644 man/example_data.Rd diff --git a/R/data.R b/R/data.R new file mode 100644 index 0000000..be00067 --- /dev/null +++ b/R/data.R @@ -0,0 +1,11 @@ +#' Example dataset +#' +#' A dataset containing a matrix with two columns that were generated +#' with a random normal distribution with a mean of 0 and stdev of 1. +#' +#' @format A matrix with 100 rows and 2 columns +#' @keywords datasets +#' @usage data("example_data") +#' @examples +#' data("example_data") +"example_data" \ No newline at end of file diff --git a/data-raw/example_data.R b/data-raw/example_data.R new file mode 100644 index 0000000..24efc73 --- /dev/null +++ b/data-raw/example_data.R @@ -0,0 +1,6 @@ +## code to prepare `example_data` dataset goes here +set.seed(123) +a <- rnorm(100) +b <- rnorm(100) +example_data <- cbind(a, b) +usethis::use_data(example_data, overwrite = TRUE) diff --git a/man/example_data.Rd b/man/example_data.Rd new file mode 100644 index 0000000..e724347 --- /dev/null +++ b/man/example_data.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{example_data} +\alias{example_data} +\title{Example dataset} +\format{ +A matrix with 100 rows and 2 columns +} +\usage{ +data("example_data") +} +\description{ +A dataset containing a matrix with two columns that were generated +with a random normal distribution with a mean of 0 and stdev of 1. +} +\examples{ +data("example_data") +} +\keyword{datasets} From d017c99b7eb748214f7755b6cb17b90297c19a7d Mon Sep 17 00:00:00 2001 From: Amulya Shastry Date: Wed, 25 May 2022 13:05:01 -0400 Subject: [PATCH 2/2] Adding function --- .Rbuildignore | 4 + .gitignore | 8 + DESCRIPTION | 6 +- NAMESPACE | 1 + NEWS.md | 3 + R/data.R | 4 +- R/distance.R | 31 ++ _pkgdown.yml | 4 + data/example_data.rda | Bin 0 -> 2011 bytes man/euclideanDist.Rd | 27 ++ renv.lock | 735 ++++++++++++++++++++++++++++++++ tests/testthat/test-distance.R | 3 + tests/testthat/test-euclidean.R | 9 + vignettes/DevelExample.Rmd | 14 + 14 files changed, 845 insertions(+), 4 deletions(-) create mode 100644 R/distance.R create mode 100644 data/example_data.rda create mode 100644 man/euclideanDist.Rd create mode 100644 renv.lock create mode 100644 tests/testthat/test-distance.R create mode 100644 tests/testthat/test-euclidean.R diff --git a/.Rbuildignore b/.Rbuildignore index 88b0533..f03f591 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ +^renv$ +^renv\.lock$ ^LICENSE\.md$ ^.*\.Rproj$ ^\.Rproj\.user$ @@ -6,3 +8,5 @@ ^docs$ ^pkgdown$ ^\.lintr$ +renv* +^data-raw$ diff --git a/.gitignore b/.gitignore index 0dddc4b..0baf90b 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,11 @@ vignettes/*.pdf .Renviron inst/doc docs + +# Adding this to not track local libs + +.Rprofile +renv/ + + + diff --git a/DESCRIPTION b/DESCRIPTION index e2161da..7b71f6e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: DevelExample Title: A Basic R Package to Demonstrate a Cycle of Code Development -Version: 0.0.1 +Version: 0.1.0 Authors@R: person(given = "Joshua", family = "Campbell", @@ -15,10 +15,12 @@ Encoding: UTF-8 biocViews: Clustering LazyData: false Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.0 Suggests: knitr, rmarkdown, testthat (>= 3.0.0) Config/testthat/edition: 3 VignetteBuilder: knitr +Depends: + R (>= 2.10) diff --git a/NAMESPACE b/NAMESPACE index 01843dc..6bd620a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,3 +1,4 @@ # Generated by roxygen2: do not edit by hand +export(euclideanDist) export(hello) diff --git a/NEWS.md b/NEWS.md index 4cd8ae2..813a54d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,3 +3,6 @@ * Added Hello World function * Added documentation, unit tests, and vignettes * Added a `NEWS.md` file to track changes to the package. + +# Changes in Version 0.1.0 (2022-05-20) +* Added function to calculate euclidean distance \ No newline at end of file diff --git a/R/data.R b/R/data.R index be00067..394dcb5 100644 --- a/R/data.R +++ b/R/data.R @@ -1,11 +1,11 @@ #' Example dataset #' #' A dataset containing a matrix with two columns that were generated -#' with a random normal distribution with a mean of 0 and stdev of 1. +#' with a random normal distribution with a mean of 0 and stdev of 1. #' #' @format A matrix with 100 rows and 2 columns #' @keywords datasets #' @usage data("example_data") #' @examples #' data("example_data") -"example_data" \ No newline at end of file +"example_data" diff --git a/R/distance.R b/R/distance.R new file mode 100644 index 0000000..4c868dc --- /dev/null +++ b/R/distance.R @@ -0,0 +1,31 @@ +#' @title Euclidean distance +#' @description Calculates Euclidean distance between two vectors. +#' An error will be given if NAs are present in either vector. +#' @param a The first vector to use in the distance calculation. +#' @param b The second vector to use in the distance calculation. +#' @param verbose Boolean. If \code{TRUE}, a message will be printed. +#' Default \code{TRUE}. +#' @return A numeric value of a distance +#' @examples +#' data(example_data) +#' euclideanDist(example_data[, 1], example_data[, 2], verbose = FALSE) +#' @export +euclideanDist <- function(a, b, verbose = FALSE) { + if (isTRUE(verbose)) { + message("Calculating distance ...") + } + + # Check validity of data + .checkData(a) + .checkData(b) + + # Perform calculation + res <- sqrt(sum((a - b)^2)) + return(res) +} + +.checkData <- function(input) { + if (any(is.na(input))) { + stop("'input' must not contain NAs") + } +} diff --git a/_pkgdown.yml b/_pkgdown.yml index e69de29..d71acfb 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: ~ +template: + bootstrap: 5 + diff --git a/data/example_data.rda b/data/example_data.rda new file mode 100644 index 0000000000000000000000000000000000000000..6096c6b99e898338ce33f497c58f83fbfc8f84bf GIT binary patch literal 2011 zcmV<12PF7HT4*^jL0KkKS?5?>qW}RifB*mg|NsC0|NsC0|NsC0|NsC0|NsC0|NsC0 z|NsC0|NqbgeqQEVJ=A7O@B$Mjg)`D8q+)2%>7qSD(3)+iftf~)G-;-TO*W>Uka~|$ z(=;?j)X>CwntGaMqehQJXgwxFPgB(O83&*cJb=_`=tfT|>VB!@o{{KjqG1DMY7%2f z`liZerk;}#vYDpU9-}l(G{|K1Luv*_Bh>XCnns?dr1dtTqttm#FhPj)(mhX83FLz` zPbsv4=@>GeqtPCkf$AQiS z0z5zn^)aSIdI^(iW`s1+lLCIAXiNynh}sc=8UZxX>8a^5GHHZqngqzeCO}MR00000 z0Wb{!GynhrpiCnG000006HTB127mwnMhSpMOojje000D2(?}GVqGTF9MvQ=H2AW|q z13{6KL8C^1(At_A14B&!(@hNqMn|F=05s6akO0sz28XE713{3@APokArb8g8Gc{xy zRwAf`Elz2Yuq%$t2m;}yM92aFA_7ea7=SA10Dx0Kv2Q*0afuLu3K$Fn<-Fe=l0hUE z2m+-v&iVC8uMzHkqD24?Zz9}B*R{+>WmoAXLx-kK3Y5Gdiyx8)G-2t<(w+7YHbI$@ z!IwrcNK2xRTBb1`AF=nymXZyY zWFZw{_yl<%qxg`9cl)|6!4neEzB;bty?Y+LAHzB3O4(Oe$-=7%(NG~tsbDfE9yO*O z0kSDFw4R3*6M6JfTJ1&b;Se)Pv{ct-a@V*2et9B(CVr_wXTXB>AwbK6TR(bW78lTG z9ix^Zf@Qd+ObXTS(y?(Jw?z87c~Z5U1tQ~2oB6x26^<^7ZE`fb>ZWu^-#nA=tcB3O zqDt_>SdE1(&EN1`y25FL&**$fFb%!Pf^Z+1Ik+1-M6jRo-K7#5`QSO(9g^{HJPQvF zlV<63B}4#vDmPaQ$;$$pU}+NcL^N|& z&@SNriZixkBe+UM(htuLG7YAu6h0I5dI?lNH(6R}b{At%i#P)LgGuW&ZQNFAo}ms+ zQ?3}UJzKyk`G!eiUtJ7i6_>V2Y7#X(PtOcv<1`&4CeP+CvU#Rq>G~R^iw>4+BDI^T zzDno1I78X8bxvQl983&ka*<r228iqTFL zz*ACn(juh2$a`NBtAR2J`#jE+>IEed~hvaM4;*x|DcghD}wK1vQ7hiG79 zs2rf+Q!|DM_hZLjUf6JR&_FU*T$WAjIc-ZRyLvXcp}yGm+CELwux0P^>U!_xM5wbQ zI>%b^A12#eVe*Ed5V%LR-wXh5aikx7Xg%198jc^IuWjUK4`1ng&|6BoUFcU%kP;a- zOHYvxF7Tp2TF563iRw>;DOd-=rUQCNnhg+&A$GK+QcQ}8?c?BoW!aF+Oo$qgpbhkj zmoE;_1BX1u7-2j9?QsIg!96=TDCkz{?1&J^*}>Z+i4<Ny9^<8( zsn*6vx=ry@+R{+1b%CNx;;?6NwM5nGH|aw+4Bp+P8g@JwECb^wIYSF+pay(cOR*_YWG^2_Br#|N8LpLVWDQU@V%(EHIiU#%rC9S%uDX``}{=<_Ct}&N z)d}HQ?o-B~nM?Ab;!2tyesFh#ttJ#hK=7N>y~LleMo|F}ih$P<#RoO?oWr9eyY5Gk zsv;kmv1DPWF@!`g_RpbuMpeu4jOa2cN@oiMTx%*K6_J{gI1uJ;RZC?MN%+ tMncfiR4od>uTcBsta>D8ODtsmK5T literal 0 HcmV?d00001 diff --git a/man/euclideanDist.Rd b/man/euclideanDist.Rd new file mode 100644 index 0000000..47130b4 --- /dev/null +++ b/man/euclideanDist.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/distance.R +\name{euclideanDist} +\alias{euclideanDist} +\title{Euclidean distance} +\usage{ +euclideanDist(a, b, verbose = FALSE) +} +\arguments{ +\item{a}{The first vector to use in the distance calculation.} + +\item{b}{The second vector to use in the distance calculation.} + +\item{verbose}{Boolean. If \code{TRUE}, a message will be printed. +Default \code{TRUE}.} +} +\value{ +A numeric value of a distance +} +\description{ +Calculates Euclidean distance between two vectors. +An error will be given if NAs are present in either vector. +} +\examples{ +data(example_data) +euclideanDist(example_data[, 1], example_data[, 2], verbose = FALSE) +} diff --git a/renv.lock b/renv.lock new file mode 100644 index 0000000..f5f5ce5 --- /dev/null +++ b/renv.lock @@ -0,0 +1,735 @@ +{ + "R": { + "Version": "4.1.2", + "Repositories": [ + { + "Name": "BioCsoft", + "URL": "https://bioconductor.org/packages/3.14/bioc" + }, + { + "Name": "BioCann", + "URL": "https://bioconductor.org/packages/3.14/data/annotation" + }, + { + "Name": "BioCexp", + "URL": "https://bioconductor.org/packages/3.14/data/experiment" + }, + { + "Name": "BioCworkflows", + "URL": "https://bioconductor.org/packages/3.14/workflows" + }, + { + "Name": "BioCbooks", + "URL": "https://bioconductor.org/packages/3.14/books" + }, + { + "Name": "CRAN", + "URL": "https://cran.rstudio.com" + } + ] + }, + "Packages": { + "R6": { + "Package": "R6", + "Version": "2.5.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "470851b6d5d0ac559e9d01bb352b4021", + "Requirements": [] + }, + "askpass": { + "Package": "askpass", + "Version": "1.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "e8a22846fff485f0be3770c2da758713", + "Requirements": [ + "sys" + ] + }, + "base64enc": { + "Package": "base64enc", + "Version": "0.1-3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "543776ae6848fde2f48ff3816d0628bc", + "Requirements": [] + }, + "brio": { + "Package": "brio", + "Version": "1.1.3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "976cf154dfb043c012d87cddd8bca363", + "Requirements": [] + }, + "bslib": { + "Package": "bslib", + "Version": "0.3.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "56ae7e1987b340186a8a5a157c2ec358", + "Requirements": [ + "htmltools", + "jquerylib", + "jsonlite", + "rlang", + "sass" + ] + }, + "cachem": { + "Package": "cachem", + "Version": "1.0.6", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "648c5b3d71e6a37e3043617489a0a0e9", + "Requirements": [ + "fastmap", + "rlang" + ] + }, + "callr": { + "Package": "callr", + "Version": "3.7.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "461aa75a11ce2400245190ef5d3995df", + "Requirements": [ + "R6", + "processx" + ] + }, + "cli": { + "Package": "cli", + "Version": "3.3.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "23abf173c2b783dcc43379ab9bba00ee", + "Requirements": [ + "glue" + ] + }, + "cpp11": { + "Package": "cpp11", + "Version": "0.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "fa53ce256cd280f468c080a58ea5ba8c", + "Requirements": [] + }, + "crayon": { + "Package": "crayon", + "Version": "1.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "0a6a65d92bd45b47b94b84244b528d17", + "Requirements": [] + }, + "curl": { + "Package": "curl", + "Version": "4.3.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "022c42d49c28e95d69ca60446dbabf88", + "Requirements": [] + }, + "desc": { + "Package": "desc", + "Version": "1.4.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "28763d08fadd0b733e3cee9dab4e12fe", + "Requirements": [ + "R6", + "crayon", + "rprojroot" + ] + }, + "diffobj": { + "Package": "diffobj", + "Version": "0.3.5", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "bcaa8b95f8d7d01a5dedfd959ce88ab8", + "Requirements": [ + "crayon" + ] + }, + "digest": { + "Package": "digest", + "Version": "0.6.29", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "cf6b206a045a684728c3267ef7596190", + "Requirements": [] + }, + "downlit": { + "Package": "downlit", + "Version": "0.4.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "ba63dc9ab5a31f3209892437e40c5f60", + "Requirements": [ + "brio", + "desc", + "digest", + "evaluate", + "fansi", + "memoise", + "rlang", + "vctrs", + "yaml" + ] + }, + "ellipsis": { + "Package": "ellipsis", + "Version": "0.3.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077", + "Requirements": [ + "rlang" + ] + }, + "evaluate": { + "Package": "evaluate", + "Version": "0.15", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "699a7a93d08c962d9f8950b2d7a227f1", + "Requirements": [] + }, + "fansi": { + "Package": "fansi", + "Version": "1.0.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "f28149c2d7a1342a834b314e95e67260", + "Requirements": [] + }, + "fastmap": { + "Package": "fastmap", + "Version": "1.1.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "77bd60a6157420d4ffa93b27cf6a58b8", + "Requirements": [] + }, + "fs": { + "Package": "fs", + "Version": "1.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "7c89603d81793f0d5486d91ab1fc6f1d", + "Requirements": [] + }, + "glue": { + "Package": "glue", + "Version": "1.6.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "de07842fc27ebf60e1102091c0c85e47", + "Requirements": [] + }, + "highr": { + "Package": "highr", + "Version": "0.9", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "8eb36c8125038e648e5d111c0d7b2ed4", + "Requirements": [ + "xfun" + ] + }, + "htmltools": { + "Package": "htmltools", + "Version": "0.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "526c484233f42522278ab06fb185cb26", + "Requirements": [ + "base64enc", + "digest", + "fastmap", + "rlang" + ] + }, + "httr": { + "Package": "httr", + "Version": "1.4.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "a525aba14184fec243f9eaec62fbed43", + "Requirements": [ + "R6", + "curl", + "jsonlite", + "mime", + "openssl" + ] + }, + "jquerylib": { + "Package": "jquerylib", + "Version": "0.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "5aab57a3bd297eee1c1d862735972182", + "Requirements": [ + "htmltools" + ] + }, + "jsonlite": { + "Package": "jsonlite", + "Version": "1.7.3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "68c37fd8f863c6273dcd24928c17d6e1", + "Requirements": [] + }, + "knitr": { + "Package": "knitr", + "Version": "1.39", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "029ab7c4badd3cf8af69016b2ba27493", + "Requirements": [ + "evaluate", + "highr", + "stringr", + "xfun", + "yaml" + ] + }, + "lifecycle": { + "Package": "lifecycle", + "Version": "1.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "a6b6d352e3ed897373ab19d8395c98d0", + "Requirements": [ + "glue", + "rlang" + ] + }, + "magrittr": { + "Package": "magrittr", + "Version": "2.0.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "cdc87ecd81934679d1557633d8e1fe51", + "Requirements": [] + }, + "memoise": { + "Package": "memoise", + "Version": "2.0.1", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c", + "Requirements": [ + "cachem", + "rlang" + ] + }, + "mime": { + "Package": "mime", + "Version": "0.12", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "18e9c28c1d3ca1560ce30658b22ce104", + "Requirements": [] + }, + "openssl": { + "Package": "openssl", + "Version": "1.4.6", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "69fdf291af288f32fd4cd93315084ea8", + "Requirements": [ + "askpass" + ] + }, + "pillar": { + "Package": "pillar", + "Version": "1.7.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "51dfc97e1b7069e9f7e6f83f3589c22e", + "Requirements": [ + "cli", + "crayon", + "ellipsis", + "fansi", + "glue", + "lifecycle", + "rlang", + "utf8", + "vctrs" + ] + }, + "pkgconfig": { + "Package": "pkgconfig", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "01f28d4278f15c76cddbea05899c5d6f", + "Requirements": [] + }, + "pkgdown": { + "Package": "pkgdown", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "ec3139021900fa27faae7a821b732bf8", + "Requirements": [ + "bslib", + "callr", + "crayon", + "desc", + "digest", + "downlit", + "fs", + "httr", + "jsonlite", + "magrittr", + "memoise", + "purrr", + "ragg", + "rlang", + "rmarkdown", + "tibble", + "whisker", + "withr", + "xml2", + "yaml" + ] + }, + "pkgload": { + "Package": "pkgload", + "Version": "1.2.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "7533cd805940821bf23eaf3c8d4c1735", + "Requirements": [ + "cli", + "crayon", + "desc", + "rlang", + "rprojroot", + "rstudioapi", + "withr" + ] + }, + "praise": { + "Package": "praise", + "Version": "1.0.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "a555924add98c99d2f411e37e7d25e9f", + "Requirements": [] + }, + "processx": { + "Package": "processx", + "Version": "3.5.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "0cbca2bc4d16525d009c4dbba156b37c", + "Requirements": [ + "R6", + "ps" + ] + }, + "ps": { + "Package": "ps", + "Version": "1.6.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "32620e2001c1dce1af49c49dccbb9420", + "Requirements": [] + }, + "purrr": { + "Package": "purrr", + "Version": "0.3.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "97def703420c8ab10d8f0e6c72101e02", + "Requirements": [ + "magrittr", + "rlang" + ] + }, + "ragg": { + "Package": "ragg", + "Version": "1.2.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "14932bb6f2739c771ca4ceaba6b4248e", + "Requirements": [ + "systemfonts", + "textshaping" + ] + }, + "rappdirs": { + "Package": "rappdirs", + "Version": "0.3.3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "5e3c5dc0b071b21fa128676560dbe94d", + "Requirements": [] + }, + "rematch2": { + "Package": "rematch2", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "76c9e04c712a05848ae7a23d2f170a40", + "Requirements": [ + "tibble" + ] + }, + "renv": { + "Package": "renv", + "Version": "0.15.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "c1078316e1d4f70275fc1ea60c0bc431", + "Requirements": [] + }, + "rlang": { + "Package": "rlang", + "Version": "1.0.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "04884d9a75d778aca22c7154b8333ec9", + "Requirements": [] + }, + "rmarkdown": { + "Package": "rmarkdown", + "Version": "2.14", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "31b60a882fabfabf6785b8599ffeb8ba", + "Requirements": [ + "bslib", + "evaluate", + "htmltools", + "jquerylib", + "jsonlite", + "knitr", + "stringr", + "tinytex", + "xfun", + "yaml" + ] + }, + "rprojroot": { + "Package": "rprojroot", + "Version": "2.0.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "249d8cd1e74a8f6a26194a91b47f21d1", + "Requirements": [] + }, + "rstudioapi": { + "Package": "rstudioapi", + "Version": "0.13", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "06c85365a03fdaf699966cc1d3cf53ea", + "Requirements": [] + }, + "sass": { + "Package": "sass", + "Version": "0.4.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "50cf822feb64bb3977bda0b7091be623", + "Requirements": [ + "R6", + "fs", + "htmltools", + "rappdirs", + "rlang" + ] + }, + "stringi": { + "Package": "stringi", + "Version": "1.7.6", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "bba431031d30789535745a9627ac9271", + "Requirements": [] + }, + "stringr": { + "Package": "stringr", + "Version": "1.4.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "0759e6b6c0957edb1311028a49a35e76", + "Requirements": [ + "glue", + "magrittr", + "stringi" + ] + }, + "sys": { + "Package": "sys", + "Version": "3.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "b227d13e29222b4574486cfcbde077fa", + "Requirements": [] + }, + "systemfonts": { + "Package": "systemfonts", + "Version": "1.0.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "90b28393209827327de889f49935140a", + "Requirements": [ + "cpp11" + ] + }, + "testthat": { + "Package": "testthat", + "Version": "3.1.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "f76c2a02d0fdc24aa7a47ea34261a6e3", + "Requirements": [ + "R6", + "brio", + "callr", + "cli", + "crayon", + "desc", + "digest", + "ellipsis", + "evaluate", + "jsonlite", + "lifecycle", + "magrittr", + "pkgload", + "praise", + "processx", + "ps", + "rlang", + "waldo", + "withr" + ] + }, + "textshaping": { + "Package": "textshaping", + "Version": "0.3.6", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "1ab6223d3670fac7143202cb6a2d43d5", + "Requirements": [ + "cpp11", + "systemfonts" + ] + }, + "tibble": { + "Package": "tibble", + "Version": "3.1.6", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "8a8f02d1934dfd6431c671361510dd0b", + "Requirements": [ + "ellipsis", + "fansi", + "lifecycle", + "magrittr", + "pillar", + "pkgconfig", + "rlang", + "vctrs" + ] + }, + "tinytex": { + "Package": "tinytex", + "Version": "0.36", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "130fe4c61e55b271a2655b3a284a205f", + "Requirements": [ + "xfun" + ] + }, + "utf8": { + "Package": "utf8", + "Version": "1.2.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "c9c462b759a5cc844ae25b5942654d13", + "Requirements": [] + }, + "vctrs": { + "Package": "vctrs", + "Version": "0.3.8", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "ecf749a1b39ea72bd9b51b76292261f1", + "Requirements": [ + "ellipsis", + "glue", + "rlang" + ] + }, + "waldo": { + "Package": "waldo", + "Version": "0.4.0", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "035fba89d0c86e2113120f93301b98ad", + "Requirements": [ + "cli", + "diffobj", + "fansi", + "glue", + "rematch2", + "rlang", + "tibble" + ] + }, + "whisker": { + "Package": "whisker", + "Version": "0.4", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "ca970b96d894e90397ed20637a0c1bbe", + "Requirements": [] + }, + "withr": { + "Package": "withr", + "Version": "2.4.3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "a376b424c4817cda4920bbbeb3364e85", + "Requirements": [] + }, + "xfun": { + "Package": "xfun", + "Version": "0.29", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "e2e5fb1a74fbb68b27d6efc5372635dc", + "Requirements": [] + }, + "xml2": { + "Package": "xml2", + "Version": "1.3.3", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "40682ed6a969ea5abfd351eb67833adc", + "Requirements": [] + }, + "yaml": { + "Package": "yaml", + "Version": "2.2.2", + "Source": "Repository", + "Repository": "CRAN", + "Hash": "4597f73aad7d32c2913ec33a345f900b", + "Requirements": [] + } + } +} diff --git a/tests/testthat/test-distance.R b/tests/testthat/test-distance.R new file mode 100644 index 0000000..8849056 --- /dev/null +++ b/tests/testthat/test-distance.R @@ -0,0 +1,3 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +}) diff --git a/tests/testthat/test-euclidean.R b/tests/testthat/test-euclidean.R new file mode 100644 index 0000000..19ddcd0 --- /dev/null +++ b/tests/testthat/test-euclidean.R @@ -0,0 +1,9 @@ +library("DevelExample") +data(example_data) + +test_that("Testing euclideanDist function", { + res <- dist(rbind(example_data[, 1], example_data[, 2]))[1] + expect_equal(euclideanDist(example_data[, 1], example_data[, 2]), res) + + expect_error(euclideanDist(c(1, 2), c(NA, 2)), regexp = "contain NAs") +}) diff --git a/vignettes/DevelExample.Rmd b/vignettes/DevelExample.Rmd index 170fadb..c75f673 100644 --- a/vignettes/DevelExample.Rmd +++ b/vignettes/DevelExample.Rmd @@ -34,9 +34,23 @@ We can also run the same function but without all of the exclamation marks: hello(withExcitement = FALSE) ``` +To calculate the euclidean distance between two vectors, we can use the `euclideanDist` function. In this example we will generate two random vectors from normal distributions with two different means and calculate the distance between them: + +```{r dist} +set.seed(12345) +v1 <- rnorm(10000, mean = 1) +v2 <- rnorm(10000, mean = 2) +res <- euclideanDist(v1, v2, verbose = FALSE) +res +``` + +The `set.seed` function is used for the random number generator and ensures the same vectors will be produced each time for reproducibility. + It is usually a good idea to show the session information to help with reproducibility: ```{r session} sessionInfo() ``` + +