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
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^renv$
^renv\.lock$
^LICENSE\.md$
^.*\.Rproj$
^\.Rproj\.user$
Expand All @@ -6,3 +8,5 @@
^docs$
^pkgdown$
^\.lintr$
^renv*$
^data-raw$
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
extra-packages: lintr

- name: Lint
run: lintr::lint_package()
run: lintr::lint_package(linters = lintr::linters_with_defaults(object_name_linter = lintr::object_name_linter("camelCase")))
shell: Rscript {0}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ vignettes/*.pdf
.Renviron
inst/doc
docs

# Local libraries
.Rprofile
renv/
2 changes: 1 addition & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
linters: with_defaults(
linters: linters_with_defaults(
object_name_linter = object_name_linter(styles = "camelCase"),
line_length_linter(80),
T_and_F_symbol_linter
Expand Down
8 changes: 5 additions & 3 deletions 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 @@ -15,10 +15,12 @@ Encoding: UTF-8
biocViews: Clustering
LazyData: false
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.2.1
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0)
testthat,
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)
9 changes: 5 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changes in Version 0.0.1 (2022-05-08)
* Created package
* Added Hello World function
* Added documentation, unit tests, and vignettes
# Changes in Version 0.1.0 (2022-05-20)
* Added function to calculate euclidean distance

# DevelExample 0.1.0

* Added a `NEWS.md` file to track changes to the package.
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("exampleData")
#' @examples
#' data("exampleData")
"exampleData"
32 changes: 32 additions & 0 deletions R/distance.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' @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(exampleData)
#' euclideanDist(exampleData[, 1], exampleData[, 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")
}
}
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: ~
template:
bootstrap: 5

6 changes: 6 additions & 0 deletions data-raw/exampleData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## code to prepare `exampleData` dataset goes here
set.seed(123)
a <- rnorm(100)
b <- rnorm(100)
exampleData <- cbind(a, b)
usethis::use_data(exampleData, overwrite = TRUE)
Binary file added data/exampleData.rda
Binary file not shown.
27 changes: 27 additions & 0 deletions man/euclideanDist.Rd

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

20 changes: 20 additions & 0 deletions man/exampleData.Rd

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

Loading