diff --git a/.Rbuildignore b/.Rbuildignore index 88b0533..c1f5b85 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ +^renv$ +^renv\.lock$ ^LICENSE\.md$ ^.*\.Rproj$ ^\.Rproj\.user$ @@ -6,3 +8,4 @@ ^docs$ ^pkgdown$ ^\.lintr$ +^data-raw$ diff --git a/.Rprofile b/.Rprofile new file mode 100644 index 0000000..81b960f --- /dev/null +++ b/.Rprofile @@ -0,0 +1 @@ +source("renv/activate.R") diff --git a/.github/workflows/BioC-check.yaml b/.github/workflows/BioC-check.yaml index cd13eff..659030e 100644 --- a/.github/workflows/BioC-check.yaml +++ b/.github/workflows/BioC-check.yaml @@ -25,17 +25,17 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: rcmdcheck, BiocManager diff --git a/DESCRIPTION b/DESCRIPTION index e2161da..5884c4a 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.3 Suggests: knitr, rmarkdown, testthat (>= 3.0.0) Config/testthat/edition: 3 VignetteBuilder: knitr +Depends: + R (>= 2.10) diff --git a/NEWS.md b/NEWS.md index 4cd8ae2..eaad579 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,3 @@ -# Changes in Version 0.0.1 (2022-05-08) -* Created package -* Added Hello World function -* Added documentation, unit tests, and vignettes -* Added a `NEWS.md` file to track changes to the package. +# DevelExample 0.1.0 + +* Initial CRAN submission. 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/R/distance.R b/R/distance.R new file mode 100644 index 0000000..054f88c --- /dev/null +++ b/R/distance.R @@ -0,0 +1,19 @@ +euclideanDist <- function(a, b, verbose = FALSE) { + if (isTRUE(verbose)) { + message("Calculating distance ...") + } + + # Check validity of data + .check_data(a) + .check_data(b) + + # Perform calculation + res <- sqrt(sum((a-b)^2)) + return(res) +} + +.check_data <- function(input) { + if (any(is.na(input))) { + stop("'input' must not contain NAs") + } +} \ No newline at end of file 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-raw/example_data.R b/data-raw/example_data.R new file mode 100644 index 0000000..6521d8a --- /dev/null +++ b/data-raw/example_data.R @@ -0,0 +1,7 @@ +## code to prepare `example_data` dataset goes here +## 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/data/example_data.rda b/data/example_data.rda new file mode 100644 index 0000000..c16d432 Binary files /dev/null and b/data/example_data.rda differ diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..11eae1d --- /dev/null +++ b/docs/404.html @@ -0,0 +1,86 @@ + + +
+ + + + +MIT License + +Copyright (c) 2022 campbio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. ++ +
Copyright (c) 2022 DevelExample authors
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+DevelExample.RmdThis is a simple vignette to demonstrate the functions that are available in the DevelExample package. The purpose of this package is to demonstrate the process of adding code to an R function. The full tutorial “Adding code to an R package” can be found at the Campbell lab website under the “Articles” tab.
+Let’s first load the library:
+
+library(DevelExample)Next we can run our function with default parameters:
+
+hello()
+#> [1] "Hello world!!!"We can also run the same function but without all of the exclamation marks:
+
+hello(withExcitement = FALSE)
+#> [1] "Hello world."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:
+set.seed(12345)
+v1 <- rnorm(10000, mean = 1)
+v2 <- rnorm(10000, mean = 2)
+res <- euclideanDist(v1, v2, verbose = FALSE)
+res
+#> [1] 171.4371The 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:
+
+sessionInfo()
+#> R version 4.0.2 (2020-06-22)
+#> Platform: x86_64-apple-darwin17.0 (64-bit)
+#> Running under: macOS 10.16
+#>
+#> Matrix products: default
+#> BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
+#> LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
+#>
+#> locale:
+#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
+#>
+#> attached base packages:
+#> [1] stats graphics grDevices utils datasets methods base
+#>
+#> other attached packages:
+#> [1] DevelExample_0.1.0
+#>
+#> loaded via a namespace (and not attached):
+#> [1] rstudioapi_0.13 knitr_1.39 magrittr_2.0.1 R6_2.5.0
+#> [5] ragg_1.1.3 rlang_1.0.2 fastmap_1.1.0 stringr_1.4.0
+#> [9] tools_4.0.2 xfun_0.30 cli_3.3.0 jquerylib_0.1.3
+#> [13] htmltools_0.5.2 systemfonts_1.0.1 yaml_2.2.1 digest_0.6.27
+#> [17] rprojroot_2.0.2 pkgdown_2.0.3 crayon_1.4.1 textshaping_0.3.5
+#> [21] purrr_0.3.4 sass_0.4.1 fs_1.5.0 memoise_2.0.0
+#> [25] cachem_1.0.4 evaluate_0.15 rmarkdown_2.14 stringi_1.5.3
+#> [29] compiler_4.0.2 bslib_0.3.1 desc_1.3.0 jsonlite_1.7.2dot-checkData.RdThis functions checks for NAs in a vector
+.checkData(input)A numeric vector
Nothing returned
+euclideanDist.RdCalculates Euclidean distance between two vectors. An error +will be given if NAs are present in either vector.
+euclideanDist(a, b, verbose = FALSE)The first vector to use in the distance calculation.
The second vector to use in the distance calculation.
Boolean. If TRUE, a message will be printed.
+Default TRUE.
A numeric value of a distance
+data(example_data)
+euclideanDist(example_data[,1], example_data[,2], verbose = FALSE)
+#> [1] 13.69805
+example_data
+ hello()
+