Skip to content

Commit 7ad1e01

Browse files
committed
finished metrics & statistics test that
1 parent 59576c5 commit 7ad1e01

27 files changed

Lines changed: 1500 additions & 363 deletions

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
- test-util-combine_conditions.R
2323
- test-util-matrix_to_dtable.R
2424
- test-util-wholenumber.R
25+
- test-metrics-diversity.R
26+
- test-metrics-hill_taxa.R
27+
- test-metrics-distances.R
28+
- test-statistics-pairwise_stats.R
29+
- test-visualisation-diversity_plot.R [TODO]
30+
- test-visualisation-ordination_plot.R [TODO]
31+
- test-visualisation-plot_pairwise_stats.R [TODO]
32+
- test-visualisation-volcano_plot.R [TODO]
2533
- TODO: Add `tryCatch` where neccessary
2634
- Added `tryCatch` and better error handling in `omics$sample_subset`, `omics$feature_subset` and `omics$samplepair_subset`.
2735
- Replaced `jsonlite` by `yyjsonr` functionality, much faster and cleaner code.

R/bray.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,24 @@ bray <- function(x, weighted = TRUE, threads = 1) {
4343

4444
## Error handling
4545
#--------------------------------------------------------------------#
46+
if (is.vector(x))
47+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
48+
4649
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4750
x <- methods::as(x, "CsparseMatrix")
48-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
49-
51+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
52+
5053
if (!is.numeric(x@x))
51-
cli::cli_abort("Input data must be numeric.")
54+
cli::cli_abort("{.val x} must be numeric.")
55+
56+
if (!is.logical(weighted))
57+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5258

53-
if (!is.wholenumber(threads))
59+
if (length(threads) != 1) {
60+
cli::cli_abort("{.val threads} must be a single whole number.")
61+
} else if (!is.wholenumber(threads)) {
5462
cli::cli_abort("{.val {threads}} must be a whole number.")
63+
}
5564

5665
## MAIN
5766
#--------------------------------------------------------------------#

R/canberra.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,23 @@ canberra <- function(x, weighted = TRUE, threads = 1) {
4242
## Error handling
4343
#--------------------------------------------------------------------#
4444
if (is.vector(x))
45-
cli::cli_abort("Input must a matrix of class matrix or Matrix, not a vector.")
46-
45+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
46+
4747
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4848
x <- methods::as(x, "CsparseMatrix")
49-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
50-
49+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
50+
5151
if (!is.numeric(x@x))
52-
cli::cli_abort("Input data must be numeric.")
52+
cli::cli_abort("{.val x} must be numeric.")
53+
54+
if (!is.logical(weighted))
55+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5356

54-
if (!is.wholenumber(threads))
57+
if (length(threads) != 1) {
58+
cli::cli_abort("{.val threads} must be a single whole number.")
59+
} else if (!is.wholenumber(threads)) {
5560
cli::cli_abort("{.val {threads}} must be a whole number.")
61+
}
5662

5763
## MAIN
5864
#--------------------------------------------------------------------#

R/cosine.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ cosine <- function(x, weighted = TRUE, threads = 1) {
4141

4242
## Error handling
4343
#--------------------------------------------------------------------#
44+
if (is.vector(x))
45+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
46+
4447
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4548
x <- methods::as(x, "CsparseMatrix")
46-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
47-
49+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
50+
4851
if (!is.numeric(x@x))
49-
cli::cli_abort("Input data must be numeric.")
52+
cli::cli_abort("{.val x} must be numeric.")
53+
54+
if (!is.logical(weighted))
55+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5056

51-
if (!is.wholenumber(threads))
57+
if (length(threads) != 1) {
58+
cli::cli_abort("{.val threads} must be a single whole number.")
59+
} else if (!is.wholenumber(threads)) {
5260
cli::cli_abort("{.val {threads}} must be a whole number.")
61+
}
5362

5463
## MAIN
5564
#--------------------------------------------------------------------#

R/diversity.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ diversity <- function(x,
4848

4949
## Error handling
5050
#--------------------------------------------------------------------#
51-
51+
if (is.vector(x))
52+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
53+
5254
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
5355
x <- methods::as(x, "CsparseMatrix")
54-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
56+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
5557

5658
if (any(x@x < 0, na.rm = TRUE))
57-
cli::cli_abort("Input data must be non-negative")
59+
cli::cli_abort("{.val x} must be non-negative.")
5860

5961
if (!is.logical(normalize))
6062
cli::cli_abort("{.val normalize} needs to be either `TRUE` or `FALSE`.")

R/euclidean.R

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,23 @@ euclidean <- function(x, weighted = TRUE, threads = 1) {
4040
## Error handling
4141
#--------------------------------------------------------------------#
4242
if (is.vector(x))
43-
cli::cli_abort("Input must a matrix of class matrix or Matrix, not a vector.")
44-
43+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
44+
4545
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4646
x <- methods::as(x, "CsparseMatrix")
47-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
48-
47+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
48+
4949
if (!is.numeric(x@x))
50-
cli::cli_abort("Input data must be numeric.")
50+
cli::cli_abort("{.val x} must be numeric.")
51+
52+
if (!is.logical(weighted))
53+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5154

52-
if (!is.wholenumber(threads))
55+
if (length(threads) != 1) {
56+
cli::cli_abort("{.val threads} must be a single whole number.")
57+
} else if (!is.wholenumber(threads)) {
5358
cli::cli_abort("{.val {threads}} must be a whole number.")
59+
}
5460

5561
## MAIN
5662
#--------------------------------------------------------------------#

R/hill_taxa.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ hill_taxa <- function (
4747

4848
## Error handling
4949
#--------------------------------------------------------------------#
50+
if (is.vector(x))
51+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
52+
5053
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
5154
x <- methods::as(x, "CsparseMatrix")
52-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
55+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
5356

5457
if (any(x@x < 0, na.rm = TRUE))
55-
cli::cli_abort("input data must be non-negative")
58+
cli::cli_abort("{.val x} must be non-negative.")
5659

5760
if (length(q) != 1) {
5861
cli::cli_abort("{.val {q}} needs to be a single whole number.")

R/jaccard.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,24 @@ jaccard <- function(x, weighted = TRUE, threads = 1) {
4040

4141
## Error handling
4242
#--------------------------------------------------------------------#
43+
if (is.vector(x))
44+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
45+
4346
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4447
x <- methods::as(x, "CsparseMatrix")
45-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
46-
48+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
49+
4750
if (!is.numeric(x@x))
48-
cli::cli_abort("Input data must be numeric.")
51+
cli::cli_abort("{.val x} must be numeric.")
52+
53+
if (!is.logical(weighted))
54+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
4955

50-
if (!is.wholenumber(threads))
56+
if (length(threads) != 1) {
57+
cli::cli_abort("{.val threads} must be a single whole number.")
58+
} else if (!is.wholenumber(threads)) {
5159
cli::cli_abort("{.val {threads}} must be a whole number.")
60+
}
5261

5362
## MAIN
5463
#--------------------------------------------------------------------#

R/jsd.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,27 @@ jsd <- function(x, weighted = TRUE, threads = 1) {
4242

4343
## Error handling
4444
#--------------------------------------------------------------------#
45+
if (is.vector(x))
46+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
47+
4548
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4649
x <- methods::as(x, "CsparseMatrix")
47-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
50+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
4851

4952
if (!is.numeric(x@x))
50-
cli::cli_abort("Input data must be numeric.")
53+
cli::cli_abort("{.val x} must be numeric.")
5154

5255
if (any(x@x < 0, na.rm = TRUE))
53-
cli::cli_abort("Input data must be non-negative.")
56+
cli::cli_abort("{.val x} must be non-negative.")
57+
58+
if (!is.logical(weighted))
59+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5460

55-
if (!is.wholenumber(threads))
61+
if (length(threads) != 1) {
62+
cli::cli_abort("{.val threads} must be a single whole number.")
63+
} else if (!is.wholenumber(threads)) {
5664
cli::cli_abort("{.val {threads}} must be a whole number.")
65+
}
5766

5867
## MAIN
5968
#--------------------------------------------------------------------#

R/manhattan.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ manhattan <- function(x, weighted = TRUE, threads = 1) {
4141

4242
## Error handling
4343
#--------------------------------------------------------------------#
44+
if (is.vector(x))
45+
cli::cli_abort("{.val x} must be a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}, not a {.cls vector}.")
46+
4447
if (inherits(x, "denseMatrix") || inherits(x, "matrix") || inherits(x, "sparseMatrix")) {
4548
x <- methods::as(x, "CsparseMatrix")
46-
} else cli::cli_abort("Input isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
49+
} else cli::cli_abort("{.val x} isn't a {.cls matrix}, {.cls denseMatrix} or {.cls sparseMatrix}.")
4750

4851
if (!is.numeric(x@x))
49-
cli::cli_abort("Input data must be numeric.")
52+
cli::cli_abort("{.val x} must be numeric.")
53+
54+
if (!is.logical(weighted))
55+
cli::cli_abort("{.val weighted} needs to be either `TRUE` or `FALSE`.")
5056

51-
if (!is.wholenumber(threads))
57+
if (length(threads) != 1) {
58+
cli::cli_abort("{.val threads} must be a single whole number.")
59+
} else if (!is.wholenumber(threads)) {
5260
cli::cli_abort("{.val {threads}} must be a whole number.")
61+
}
5362

5463
## MAIN
5564
#--------------------------------------------------------------------#

0 commit comments

Comments
 (0)