Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^docs$
^pkgdown$
^\.lintr$
^data-raw$
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ vignettes/*.pdf
# R Environment Variables
.Renviron
inst/doc
docs
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -22,3 +22,5 @@ Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
Depends:
R (>= 2.10)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(euclideanDist)
export(hello)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Changes in Version 0.1.0 (2022-05-20)
* Added function to calculate euclidean distance

# Changes in Version 0.0.1 (2022-05-08)
* Created package
* Added Hello World function
Expand Down
11 changes: 11 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -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"
38 changes: 38 additions & 0 deletions R/distance.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' @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)
}

#' Validity check
#'
#' This functions checks for NAs in a vector
#'
#' @param input A numeric vector
#' @return Nothing returned
.checkData <- function(input) {
if (any(is.na(input))) {
stop("'input' must not contain NAs")
}
}
6 changes: 6 additions & 0 deletions data-raw/example_data.R
Original file line number Diff line number Diff line change
@@ -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)
Binary file added data/example_data.rda
Binary file not shown.
99 changes: 99 additions & 0 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading