diff --git a/R/computeAllFreqs2.R b/R/computeAllFreqs2.R index e3f68f8..4b87fea 100644 --- a/R/computeAllFreqs2.R +++ b/R/computeAllFreqs2.R @@ -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) } \ No newline at end of file diff --git a/R/repmat.R b/R/repmat.R index 630053f..642c3cd 100644 --- a/R/repmat.R +++ b/R/repmat.R @@ -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)) diff --git a/tests/testthat/test-convertedBaseFunctions.R b/tests/testthat/test-convertedBaseFunctions.R index 66c2ac9..715fe97 100644 --- a/tests/testthat/test-convertedBaseFunctions.R +++ b/tests/testthat/test-convertedBaseFunctions.R @@ -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", {