Skip to content

Commit

Permalink
version 1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood authored and cran-robot committed Sep 4, 2021
1 parent da67a65 commit 3781c92
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 69 deletions.
9 changes: 4 additions & 5 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: dynutils
Type: Package
Title: Common Functionality for the 'dynverse' Packages
Version: 1.0.6
Version: 1.0.7
Authors@R: c(
person(
"Robrecht",
Expand All @@ -25,20 +25,19 @@ Description:
License: MIT + file LICENSE
URL: https://github.com/dynverse/dynutils
BugReports: https://github.com/dynverse/dynutils/issues
LazyData: TRUE
RoxygenNote: 7.1.1
Depends: R (>= 3.0.0)
Imports: assertthat, crayon, desc, dplyr, magrittr, Matrix, methods,
proxyC, purrr, Rcpp, remotes, stringr, tibble
Suggests: ggplot2, hdf5r, knitr, readr, rmarkdown, testthat
Suggests: covr, ggplot2, hdf5r, knitr, readr, rmarkdown, testthat
LinkingTo: Rcpp
Encoding: UTF-8
VignetteBuilder: knitr
NeedsCompilation: yes
Packaged: 2021-03-22 11:24:41 UTC; rcannood
Packaged: 2021-09-02 08:33:19 UTC; rcannood
Author: Robrecht Cannoodt [aut, cre] (<https://orcid.org/0000-0003-3641-729X>,
rcannood),
Wouter Saelens [aut] (<https://orcid.org/0000-0002-7114-6248>, zouter)
Maintainer: Robrecht Cannoodt <rcannood@gmail.com>
Repository: CRAN
Date/Publication: 2021-03-22 12:50:02 UTC
Date/Publication: 2021-09-04 05:40:02 UTC
24 changes: 12 additions & 12 deletions MD5
@@ -1,17 +1,17 @@
e85f0a385a230b840f7734c355b000fe *DESCRIPTION
cfaac4514a25c22522d50186d25d3da0 *DESCRIPTION
ef3d9f056adaa322680184035912700f *LICENSE
246edeab46c29b2a202d37070ffd69ba *NAMESPACE
740331d8390bf198d01e8f7179407410 *NEWS.md
5c9dbde5719e9fb33f6d81c9470867ef *NEWS.md
dcdf2491b0e62a545623862a87d55529 *R/RcppExports.R
6f7fc8ddd74f0326bf2b59a523681cf7 *R/add_class.R
93ee58dfa8e9d0165a0aadbc62cfb01a *R/assertions.R
0b5393640d6dcc30c10bb5b9fb657769 *R/calculate_distance.R
bb6beeb3505b07b1e77e64718f3da1d2 *R/calculate_distance.R
d6aa6f13af04adf14f579e08fc13d984 *R/calculate_mean.R
e2b7b0caa56d6a39e5f74f05f1ba7546 *R/check_packages.R
cdbbf9a1f8aea5c2df485b414eed39ad *R/development.R
ebced609202a59d493b476c3aac3fe8d *R/expand_matrix.R
aa0987fdaaa50b3bf720eef589eb9cbe *R/extend_with.R
a13cca47e183757563216d56990fc82c *R/h5.R
c589a1bec773c845c2229d0a547c230c *R/h5.R
56ddd7a01d957f768e214bf3ff7d1286 *R/inherit_default_params.R
54d7dba8e284ec639517ca1e31b66a83 *R/install_packages.R
ad9da1318face1a62868506526ccb6b2 *R/mapdf.R
Expand All @@ -23,17 +23,17 @@ ad9da1318face1a62868506526ccb6b2 *R/mapdf.R
3a163b578e254a622a259fb15598b87a *R/sparse_matrix.R
ed5a6e94e1159f1aafdcfc1c82c27d49 *R/spearman_rank_sparse.R
508280137e6c0eb4d37a5872de6ab486 *R/tibble.R
e495e1e5c90fd817b8bfd8f0ebac5fc5 *README.md
41c17df5a2b8275f015aa70cfd66b3e2 *build/vignette.rds
4c7e41556e9fa4e748e25989f462b8b8 *README.md
97438e22f9f6789b6c35f75e506e56ab *build/vignette.rds
a60b55d68196751eae1016f1871240de *inst/doc/functionality.R
fd437c3c797311ac07d31ffd0e74d86c *inst/doc/functionality.Rmd
e8266682d3b17561ce09aa97af7c1a54 *inst/doc/functionality.html
4f7d145fcbf87ea6aa77b79cc43edf02 *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
0ac64cbde50d7bd409ca44d05c56366b *man/calculate_distance.Rd
2096ec04355b4f0e3a9ddd0bf91b9a47 *man/calculate_distance.Rd
5b35a6f332946299b91d087180993a29 *man/calculate_mean.Rd
3252699f0111548d1c5865b259fc6045 *man/check_packages.Rd
8119f54576526e375c65967172a35730 *man/deprecated.Rd
Expand Down Expand Up @@ -61,7 +61,7 @@ f9110f58085b0ae3ca4bc37b1bec76c9 *man/scale_uniform.Rd
8cbb41dad70d4291c45362bc92d95fec *man/switch_devel.Rd
ee0bba1b16667c4ea72c209f54ea9fa5 *man/test_h5_installation.Rd
32b3de681b6aeb351f1e91ff7add5e2b *man/tibble_as_list.Rd
8a2437afa3a3e6b7be52294db68ef331 *src/RcppExports.cpp
c22eef051e327bc12147066a9237d35c *src/RcppExports.cpp
fa89e1f21fd5ca27ac892f4ba8ba9c7c *src/project_to_segments.cpp
eab0faf9e93b86fab93ff7f4b4dc4234 *src/spearman_rank_sparse.cpp
e98edf1dd851bb968f099085613e1641 *tests/testthat.R
Expand All @@ -72,14 +72,14 @@ e98edf1dd851bb968f099085613e1641 *tests/testthat.R
dbb99d66a04da64c942eeb3d2aad76a4 *tests/testthat/test-check_packages.R
7485242237d66f602ee1126cbe4000c2 *tests/testthat/test-expand_matrix.R
8faa7d5a28c69f65e45e8ff451fc705b *tests/testthat/test-extend_with.R
6b476ee9c8230218a976b0abc9457fbf *tests/testthat/test-h5.R
057e29b12553afd78ba1f7b0ca48a03f *tests/testthat/test-h5.R
5ce31da95e0ab2cae64f31550e6957c1 *tests/testthat/test-inherit_default_params.R
eb500b1fea1726787b4e1cc25de6caa0 *tests/testthat/test-mapdf.R
87086196556352c60f0e8a21d5e13e02 *tests/testthat/test-news.R
900fd5789d675deb11cbb4c5072259e4 *tests/testthat/test-news.R
12b22a50c13f031e04cafada2045e5eb *tests/testthat/test-project_to_segments.R
15ff28feffad09aff3b062301884d6a4 *tests/testthat/test-random_time_string.R
af921049e7a8a884810b545563e80928 *tests/testthat/test-safe_tempdir.R
bacf3a9c91b28b7ab6ff90784e38ee69 *tests/testthat/test-scaling.R
5494b68645ab4526138202e62385dea5 *tests/testthat/test-spearman_rank_sparse.R
fc042589bc13e4175521bb1d10631436 *tests/testthat/test-tibble.R
360a3ba04634c17bb988f9fbe1c19f90 *tests/testthat/test-tibble.R
fd437c3c797311ac07d31ffd0e74d86c *vignettes/functionality.Rmd
12 changes: 10 additions & 2 deletions NEWS.md
@@ -1,8 +1,16 @@
# dynutils 1.0.7

* MINOR CHANGE `calculate_distance()`: Convert matrices to CsparseMatrix instead of dgCMatrix.

* MINOR CHANGE `calculate_distance()`: Pass through the `diag` argument to proxyC.

* BUG FIX unit test: Order of attributes is not relevant.

# dynutils 1.0.6

* MINOR CHANGE `calculate_distance()`: Allow for many more distance measures.
* MINOR CHANGE `calculate_distance()`: Allow for many more distance measures.

* BUG FIX: Import `desc::desc()` where needed.
* BUG FIX: Import `desc::desc()` where needed.

# dynutils 1.0.5 (2020-02-21)

Expand Down
20 changes: 13 additions & 7 deletions R/calculate_distance.R
Expand Up @@ -6,6 +6,8 @@
#' @param y (Optional) a numeric matrix, dense or sparse, with `nrow(x) == nrow(y)`.
#' @param method Which distance method to use. Options are: `"cosine"`, `"pearson"`, `"spearman"`, `"euclidean"`, and `"manhattan"`.
#' @param margin Which margin to use for the pairwise comparison. 1 => rowwise, 2 => columnwise.
#' @param diag if `TRUE`, only compute diagonal elements of the similarity/distance matrix; useful when comparing corresponding rows or columns of 'x' and 'y'.
#' @param drop0 if `TRUE`, zero values are removed regardless of min_simil or rank.
#'
#' @export
#'
Expand All @@ -27,7 +29,9 @@ calculate_distance <- function(
y = NULL,
method = c("pearson", "spearman", "cosine", "euclidean", "chisquared",
"hamming", "kullback", "manhattan", "maximum", "canberra", "minkowski"),
margin = 1
margin = 1,
diag = FALSE,
drop0 = FALSE
) {
method <- match.arg(method)
input <- .process_input_matrices(x = x, y = y, margin = margin)
Expand All @@ -36,15 +40,15 @@ calculate_distance <- function(

dis <-
if (method %in% c("cosine", "pearson", "spearman")) {
sim <- calculate_similarity(x = x, y = y, method = method, margin = 2)
sim <- calculate_similarity(x = x, y = y, method = method, margin = 2, diag = diag, drop0 = drop0)

if (method == "cosine") {
1 - 2 * acos(sim) / pi
} else {
1 - (sim + 1) / 2
}
} else {
proxyC::dist(x = x, y = y, method = method, margin = 2)
proxyC::dist(x = x, y = y, method = method, margin = 2, diag = diag, drop0 = drop0)
}

if (is.null(y)) {
Expand All @@ -65,7 +69,9 @@ calculate_similarity <- function(
x,
y = NULL,
margin = 1,
method = c("spearman", "pearson", "cosine")
method = c("spearman", "pearson", "cosine"),
diag = FALSE,
drop0 = FALSE
) {
method <- match.arg(method)
input <- .process_input_matrices(x = x, y = y, margin = margin)
Expand All @@ -83,7 +89,7 @@ calculate_similarity <- function(
method <- "correlation"
}

sim <- proxyC::simil(x = x, y = y, method = method, margin = 2)
sim <- proxyC::simil(x = x, y = y, method = method, margin = 2, diag = diag, drop0 = drop0)

# fixes due to rounding errors
if (method %in% c("pearson", "spearman", "cosine")) {
Expand All @@ -105,11 +111,11 @@ list_similarity_methods <- function() eval(formals(calculate_similarity)$method)
#' @importFrom methods as
.process_input_matrices <- function(x, y, margin) {
if (is.data.frame(x)) x <- as.matrix(x)
if (is.matrix(x)) x <- as(x, "dgCMatrix")
if (is.matrix(x)) x <- as(x, "CsparseMatrix")

if (!is.null(y)) {
if (is.data.frame(y)) y <- as.matrix(y)
if (is.matrix(y)) y <- as(y, "dgCMatrix")
if (is.matrix(y)) y <- as(y, "CsparseMatrix")
}

assert_that(
Expand Down
2 changes: 1 addition & 1 deletion R/h5.R
Expand Up @@ -166,7 +166,7 @@ write_h5_ <- function(x, file_h5, path) {
if (is.null(x)) {
hdf5r::h5attr(subfile, "object_class") <- "null"
} else if (is_sparse(x)) {
ipx <- as(x, "dgCMatrix")
ipx <- as(x, "CsparseMatrix")
hdf5r::h5attr(subfile, "object_class") <- "sparse_matrix"
subfile[["i"]] <- ipx@i
subfile[["p"]] <- ipx@p
Expand Down
17 changes: 11 additions & 6 deletions README.md
Expand Up @@ -25,17 +25,22 @@ list of changes.

<!-- This section gets automatically generated from inst/NEWS.md, and also generates inst/NEWS -->

### Recent changes in dynutils 1.0.7

- MINOR CHANGE `calculate_distance()`: Convert matrices to
CsparseMatrix instead of dgCMatrix.

- MINOR CHANGE `calculate_distance()`: Pass through the `diag`
argument to proxyC.

- BUG FIX unit test: Order of attributes is not relevant.

### Recent changes in dynutils 1.0.6

- MINOR CHANGE `calculate_distance()`: Allow for many more distance
measures.

### Recent changes in dynutils 1.0.5 (2020-02-21)

- BUG FIX `install_packages()`: will not try to install packages when
the session is not interactive.

- LICENSE: Change to MIT.
- BUG FIX: Import `desc::desc()` where needed.

## Dynverse dependencies

Expand Down
Binary file modified build/vignette.rds
Binary file not shown.
11 changes: 6 additions & 5 deletions inst/doc/functionality.html
Expand Up @@ -39,6 +39,7 @@
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
Expand Down Expand Up @@ -363,13 +364,13 @@ <h2>Manipulation of vectors</h2>
<div id="random_time_string-generates-a-string-very-likely-to-be-unique" class="section level3">
<h3><code>random_time_string</code>: Generates a string very likely to be unique</h3>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="fu">random_time_string</span>(<span class="st">&quot;test&quot;</span>)</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &quot;20210322_122440__test__syYeN626jT&quot;</span></span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &quot;20210902_103319__test__syYeN626jT&quot;</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a><span class="fu">random_time_string</span>(<span class="st">&quot;test&quot;</span>)</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &quot;20210322_122440__test__e6MCnXcJM7&quot;</span></span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &quot;20210902_103319__test__e6MCnXcJM7&quot;</span></span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a><span class="fu">random_time_string</span>(<span class="st">&quot;test&quot;</span>)</span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &quot;20210322_122440__test__9pFJ5mxS3R&quot;</span></span></code></pre></div>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &quot;20210902_103319__test__9pFJ5mxS3R&quot;</span></span></code></pre></div>
</div>
</div>
<div id="tibble-helpers" class="section level2">
Expand All @@ -384,7 +385,7 @@ <h3><code>list_as_tibble</code>: Convert a list of lists to a tibble whilst reta
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a>tib <span class="ot">&lt;-</span> <span class="fu">list_as_tibble</span>(li)</span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a>tib</span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; # A tibble: 2 x 4</span></span>
<span id="cb21-9"><a href="#cb21-9" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; # A tibble: 2 × 4</span></span>
<span id="cb21-10"><a href="#cb21-10" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; a b c .object_class</span></span>
<span id="cb21-11"><a href="#cb21-11" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; &lt;dbl&gt; &lt;list&gt; &lt;chr&gt; &lt;list&gt; </span></span>
<span id="cb21-12"><a href="#cb21-12" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; 1 1 &lt;fn&gt; parrot &lt;chr [2]&gt; </span></span>
Expand Down Expand Up @@ -475,7 +476,7 @@ <h2>File helpers</h2>
<div id="safe_tempdir-create-an-empty-temporary-directory-and-return-its-path" class="section level3">
<h3><code>safe_tempdir</code>: Create an empty temporary directory and return its path</h3>
<div class="sourceCode" id="cb28"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="fu">safe_tempdir</span>(<span class="st">&quot;samson&quot;</span>)</span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &quot;/tmp/RtmpYk0E8W/file1b5c4b27ef332b/samson&quot;</span></span></code></pre></div>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="co">#&gt; [1] &quot;/tmp/RtmpPYnzSd/file3def077bad0e06/samson&quot;</span></span></code></pre></div>
</div>
</div>
<div id="assertion-helpers" class="section level2">
Expand Down
12 changes: 10 additions & 2 deletions man/calculate_distance.Rd

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

5 changes: 5 additions & 0 deletions src/RcppExports.cpp
Expand Up @@ -5,6 +5,11 @@

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// project_to_segments
List project_to_segments(NumericMatrix x, NumericMatrix segment_start, NumericMatrix segment_end);
RcppExport SEXP _dynutils_project_to_segments(SEXP xSEXP, SEXP segment_startSEXP, SEXP segment_endSEXP) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-h5.R
Expand Up @@ -27,7 +27,7 @@ test_that("is_sparse works", {

m <- Matrix::Matrix(matrix(c(1:10)), sparse = FALSE)
expect_false(is_sparse(m))
expect_true(is_sparse(methods::as(m, "dgCMatrix")))
expect_true(is_sparse(methods::as(m, "CsparseMatrix")))
expect_false(is_sparse(methods::as(m, "dgeMatrix")))
})

Expand Down
42 changes: 21 additions & 21 deletions tests/testthat/test-news.R
Expand Up @@ -8,32 +8,32 @@ on.exit(unlink(dir_loc, recursive = TRUE))
description <- paste0(dir_loc, "/DESCRIPTION")
news_md <- paste0(dir_loc, "/NEWS.md")

readr::write_lines(c("Package: testing"), description)

readr::write_lines(c(
"# testing 0.1.1 (2019-01-02)",
" * BUG FIX: Fixing a lot of bugs!",
"",
"# testing 0.1.0 (2019-01-01)",
" * FUNCTIONALITY: Oh man I implemented so many things today!",
" I am so smart, I am so smart",
" https://media0.giphy.com/media/vLruErVSYGx8s/giphy.gif?cid=3640f6095c939f916374546263a8a301",
"",
"# testing 0.0.1 (2018-12-31)",
" * INITIAL RELEASE: super useful package!"
), news_md)

test_that("update_news works", {
# check for description
expect_error(detect_package_folder(path = dir_loc), regexp = "Could not find DESCRIPTION file")
readr::write_lines(c("Package: testing"), description)

# check for news
expect_error(find_news(path = dir_loc), regexp = "does not have a NEWS.md")
readr::write_lines(c(
"# testing 0.1.1 (2019-01-02)",
" * BUG FIX: Fixing a lot of bugs!",
"",
"# testing 0.1.0 (2019-01-01)",
" * FUNCTIONALITY: Oh man I implemented so many things today!",
" I am so smart, I am so smart",
" https://media0.giphy.com/media/vLruErVSYGx8s/giphy.gif?cid=3640f6095c939f916374546263a8a301",
"",
"# testing 0.0.1 (2018-12-31)",
" * INITIAL RELEASE: super useful package!"
), news_md)

# read news contents
recent_news <- recent_news(path = dir_loc, 2)

# check contents
expect_is(recent_news, "character")
expect_true(any(grepl("testing 0.1.1", recent_news)))
expect_false(any(grepl("testing 0.0.1", recent_news)))

file.remove(news_md)
expect_error(find_news(path = dir_loc), regexp = "does not have a NEWS.md")

file.remove(description)
expect_error(detect_package_folder(path = dir_loc), regexp = "Could not find DESCRIPTION file")
})

8 changes: 1 addition & 7 deletions tests/testthat/test-tibble.R
Expand Up @@ -17,13 +17,7 @@ tib <- tibble(
test_that("list_as_tibble works", {
tib2 <- list_as_tibble(li)

expect_equal(attributes(tib2), attributes(tib))

expect_equal(tib2$a, tib$a)
expect_equal(tib2$b, tib$b)
expect_equal(tib2$c, tib$c)
expect_equal(tib2$d, tib$d)
expect_equal(tib2$.object_class, tib$.object_class)
expect_equal(tib, tib2)
})

test_that("tibble_as_list works", {
Expand Down

0 comments on commit 3781c92

Please sign in to comment.