Improved exception handling

This commit is contained in:
Waldir Leoncio 2020-07-14 11:17:25 +02:00
parent e89c51de57
commit bb44d0cfd4
3 changed files with 6 additions and 4 deletions

View file

@ -24,6 +24,6 @@ computeAllFreqs2 <- function (noalle, COUNTS = matrix(NA, 0, 0),
}
prioriAlleelit <- repmat(prioriAlleelit, c(1, 1, npops))
counts <- COUNTS + prioriAlleelit
allFreqs <- counts / sumCounts
allFreqs <- counts / drop(sumCounts)
return(allFreqs)
}

View file

@ -13,8 +13,8 @@
repmat <- function (mx, n) {
# Validation
if (length(n) > 3) warning("Extra dimensions of n ignored")
if (!is(mx, "matrix")) mx <- t(as.matrix(mx))
if (length(n) == 1) n <- rep(n, 2)
if (!is(mx, "matrix")) mx <- as.matrix(mx)
# Replicating cols
out <- mx_col <- matrix(rep(mx, n[2]), nrow(mx))

View file

@ -11,10 +11,10 @@ test_that("repmat works properly", {
mx1 <- matrix(5:8)
mx2 <- matrix(0:-3, 2)
expect_error(repmat(mx0))
expect_equal(repmat(mx0, 1), as.matrix(mx0))
expect_equal(repmat(mx0, 1), t(as.matrix(mx0)))
expect_equal(
object = repmat(mx0, 2),
expected = unname(t(cbind(rbind(mx0, mx0), rbind(mx0, mx0))))
expected = unname(cbind(rbind(mx0, mx0), rbind(mx0, mx0)))
)
expect_equal(
object = repmat(mx1, 2),
@ -32,6 +32,8 @@ test_that("repmat works properly", {
object = repmat(mx2, c(1, 1, 2)),
expected = array(mx2, c(2, 2, 2))
)
expect_equal(repmat(1:2, 3), matrix(rep(1:2, 9), 3, 6, byrow=TRUE))
expect_equal(repmat(10, c(3, 2)), matrix(10, 3, 2))
})
test_that("zeros and ones work as expected", {