From b710d62cf7a3098b6bee8b65b60512fe7de11d66 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Tue, 11 Oct 2022 10:02:32 +0000 Subject: [PATCH] version 1.0.11 --- DESCRIPTION | 8 ++++---- MD5 | 12 ++++++------ NEWS.md | 6 +++++- R/calculate_distance.R | 12 ++++++------ inst/doc/functionality.html | 8 ++++---- man/calculate_distance.Rd | 14 +++----------- tests/testthat/test-calculate_distance.R | 4 ++-- 7 files changed, 30 insertions(+), 34 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b252f0a..373228b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: dynutils Type: Package Title: Common Functionality for the 'dynverse' Packages -Version: 1.0.10 +Version: 1.0.11 Authors@R: c( person( "Robrecht", @@ -28,16 +28,16 @@ BugReports: https://github.com/dynverse/dynutils/issues RoxygenNote: 7.2.1 Depends: R (>= 3.0.0) Imports: assertthat, crayon, desc, dplyr, magrittr, Matrix, methods, - proxyC, purrr, Rcpp, remotes, stringr, tibble + proxyC (>= 0.3.3), purrr, Rcpp, remotes, stringr, tibble Suggests: covr, ggplot2, hdf5r (>= 1.3.4), knitr, rmarkdown, testthat LinkingTo: Rcpp Encoding: UTF-8 VignetteBuilder: knitr NeedsCompilation: yes -Packaged: 2022-09-23 04:19:47 UTC; rcannood +Packaged: 2022-10-11 10:32:40 UTC; rcannood Author: Robrecht Cannoodt [aut, cre] (, rcannood), Wouter Saelens [aut] (, zouter) Maintainer: Robrecht Cannoodt Repository: CRAN -Date/Publication: 2022-09-23 04:50:03 UTC +Date/Publication: 2022-10-11 11:02:32 UTC diff --git a/MD5 b/MD5 index 83e3e71..73b39bf 100644 --- a/MD5 +++ b/MD5 @@ -1,11 +1,11 @@ -01dc47de1066237723b4b980c2a50758 *DESCRIPTION +62759b17d20b9cf1f23a6ec9b7741b59 *DESCRIPTION ef3d9f056adaa322680184035912700f *LICENSE 43a8cfbebd9b581c7f7fcb8451f7e549 *NAMESPACE -f1b5a8eee2c76519e68997f32d44e209 *NEWS.md +0ae13fab88d92acfa4f5fa07ee900a22 *NEWS.md dcdf2491b0e62a545623862a87d55529 *R/RcppExports.R 6f7fc8ddd74f0326bf2b59a523681cf7 *R/add_class.R 93ee58dfa8e9d0165a0aadbc62cfb01a *R/assertions.R -3d9950e1017544b18c403d586e21b5ff *R/calculate_distance.R +4b065a50df4879e49ce958179446d7da *R/calculate_distance.R d6aa6f13af04adf14f579e08fc13d984 *R/calculate_mean.R e2b7b0caa56d6a39e5f74f05f1ba7546 *R/check_packages.R cdbbf9a1f8aea5c2df485b414eed39ad *R/development.R @@ -27,13 +27,13 @@ ed5a6e94e1159f1aafdcfc1c82c27d49 *R/spearman_rank_sparse.R 1e902dd0285e4faae21d79ab0bef21b8 *build/vignette.rds 4cb744174c2d40de083a580148109a16 *inst/doc/functionality.R 67a99a10f52ab86808d981449e524ff3 *inst/doc/functionality.Rmd -0a06c6493c907a0806a3fd9cfdea0d12 *inst/doc/functionality.html +600abce8be96d4b1f3c373601efe6ccb *inst/doc/functionality.html c3db2b03d9fad3aa6837b3f565dfdebd *man/add_class.Rd 6bc340f4659bf12f836063f6dbdd2329 *man/all_in.Rd b5ac523861808607b014847cb3797765 *man/apply_minmax_scale.Rd 64174b3e65b65ce84ce3293ae492f994 *man/apply_quantile_scale.Rd 3bef0a231eef2816e0a263a1e4a2242c *man/apply_uniform_scale.Rd -2aee4613e71cce116c03a5d95ed45b36 *man/calculate_distance.Rd +51edf5e4b58a2ff051c209e38356a1d4 *man/calculate_distance.Rd 5b35a6f332946299b91d087180993a29 *man/calculate_mean.Rd 3252699f0111548d1c5865b259fc6045 *man/check_packages.Rd 8119f54576526e375c65967172a35730 *man/deprecated.Rd @@ -67,7 +67,7 @@ eab0faf9e93b86fab93ff7f4b4dc4234 *src/spearman_rank_sparse.cpp e98edf1dd851bb968f099085613e1641 *tests/testthat.R 90070d56ee12b1460c344b2a4dd11d46 *tests/testthat/test-add_class.R 35e9b56c7825d520e904f7fefc4bc561 *tests/testthat/test-assertions.R -77862ea764c68eca8560c52543079cb4 *tests/testthat/test-calculate_distance.R +8777dca4c3bb00d087bdf1606fa16c6d *tests/testthat/test-calculate_distance.R 6361031d09fa22e6b4cc5e705e13c726 *tests/testthat/test-calculate_mean.R dbb99d66a04da64c942eeb3d2aad76a4 *tests/testthat/test-check_packages.R 7485242237d66f602ee1126cbe4000c2 *tests/testthat/test-expand_matrix.R diff --git a/NEWS.md b/NEWS.md index 12b9c49..7df6f61 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ +# dynutils 1.0.11 + +* MINOR CHANGE: Always set `use_nan` to `TRUE`. Replace NaNs with 0 for `calculate_similarity()`. + # dynutils 1.0.10 -* MINOR CHANGE: Add `use_nan` passthrough argument for proxyC. +* MINOR CHANGE: Add `use_nan` passthrough argument for `proxyC`. # dynutils 1.0.9 diff --git a/R/calculate_distance.R b/R/calculate_distance.R index ed912aa..bff5c0e 100644 --- a/R/calculate_distance.R +++ b/R/calculate_distance.R @@ -29,8 +29,7 @@ calculate_distance <- function( "hamming", "kullback", "manhattan", "maximum", "canberra", "minkowski"), margin = 1, diag = FALSE, - drop0 = FALSE, - use_nan = FALSE + drop0 = FALSE ) { method <- match.arg(method) input <- .process_input_matrices(x = x, y = y, margin = margin) @@ -47,7 +46,7 @@ calculate_distance <- function( 1 - (sim + 1) / 2 } } else { - proxyC::dist(x = x, y = y, method = method, margin = 2, diag = diag, drop0 = drop0, use_nan = use_nan) + proxyC::dist(x = x, y = y, method = method, margin = 2, diag = diag, drop0 = drop0, use_nan = FALSE) } if (is.null(y)) { @@ -70,8 +69,7 @@ calculate_similarity <- function( margin = 1, method = c("spearman", "pearson", "cosine"), diag = FALSE, - drop0 = FALSE, - use_nan = FALSE + drop0 = FALSE ) { method <- match.arg(method) input <- .process_input_matrices(x = x, y = y, margin = margin) @@ -89,7 +87,9 @@ calculate_similarity <- function( method <- "correlation" } - sim <- proxyC::simil(x = x, y = y, method = method, margin = 2, diag = diag, drop0 = drop0, use_nan = use_nan) + sim <- proxyC::simil(x = x, y = y, method = method, margin = 2, diag = diag, drop0 = drop0, use_nan = FALSE) + # set nans to 0 + sim@x[is.nan(sim@x)] <- 0 # fixes due to rounding errors if (method %in% c("pearson", "spearman", "cosine")) { diff --git a/inst/doc/functionality.html b/inst/doc/functionality.html index cf838e5..9fb260c 100644 --- a/inst/doc/functionality.html +++ b/inst/doc/functionality.html @@ -372,13 +372,13 @@

Manipulation of vectors

random_time_string: Generates a string very likely to be unique

random_time_string("test")
-#> [1] "20220923_061947__test__syYeN626jT"
+#> [1] "20221011_123239__test__syYeN626jT"
 
 random_time_string("test")
-#> [1] "20220923_061947__test__e6MCnXcJM7"
+#> [1] "20221011_123239__test__e6MCnXcJM7"
 
 random_time_string("test")
-#> [1] "20220923_061947__test__9pFJ5mxS3R"
+#> [1] "20221011_123239__test__9pFJ5mxS3R"
@@ -484,7 +484,7 @@

File helpers

safe_tempdir: Create an empty temporary directory and return its path

safe_tempdir("samson")
-#> [1] "/tmp/RtmpsKiNj7/file28419731ffb2cf/samson"
+#> [1] "/tmp/Rtmp2aL2UF/filef21d031cfe904/samson"
diff --git a/man/calculate_distance.Rd b/man/calculate_distance.Rd index e1ad47c..cca54a1 100644 --- a/man/calculate_distance.Rd +++ b/man/calculate_distance.Rd @@ -14,8 +14,7 @@ calculate_distance( "kullback", "manhattan", "maximum", "canberra", "minkowski"), margin = 1, diag = FALSE, - drop0 = FALSE, - use_nan = FALSE + drop0 = FALSE ) list_distance_methods() @@ -26,8 +25,7 @@ calculate_similarity( margin = 1, method = c("spearman", "pearson", "cosine"), diag = FALSE, - drop0 = FALSE, - use_nan = FALSE + drop0 = FALSE ) list_similarity_methods() @@ -44,16 +42,10 @@ indicates rows or 2 indicates columns.} \item{diag}{if \code{TRUE}, only compute diagonal elements of the similarity/distance matrix; useful when comparing corresponding rows or -columns of `x` and `y`.} +columns of \code{x} and \code{y}.} \item{drop0}{if \code{TRUE}, zero values are removed regardless of \code{min_simil} or \code{rank}.} - -\item{use_nan}{if \code{TRUE}, return `NaN` if the standard deviation of a -vector is zero when `method` is "correlation"; if all the values are zero -in a vector when `method` is "cosine", "kullback", "jeffreys" or "chisquared". -Note that use of `NaN` makes the similarity/distance matrix denser and -therefore larger.} } \description{ These matrices can be dense or sparse. diff --git a/tests/testthat/test-calculate_distance.R b/tests/testthat/test-calculate_distance.R index c347b88..d10cfda 100644 --- a/tests/testthat/test-calculate_distance.R +++ b/tests/testthat/test-calculate_distance.R @@ -111,11 +111,11 @@ test_that("calculate_distance works on matrices, data frames and sparse matrices out2 <- calculate_distance(x = as.matrix(x), y = as.matrix(y), method = method) expect_equal(nrow(out2), nrow(x)) expect_equal(ncol(out2), nrow(y)) - expect_true(sum(abs(out2-out)) < 1e-10) + expect_true(sum(abs(na.omit(out2-out))) < 1e-10) out3 <- calculate_distance(x = as.data.frame(as.matrix(x)), y = as.data.frame(as.matrix(y)), method = method) expect_equal(nrow(out3), nrow(x)) expect_equal(ncol(out3), nrow(y)) - expect_true(sum(abs(out3-out)) < 1e-10) + expect_true(sum(abs(na.omit(out3-out))) < 1e-10) } })