From 37822b2ec80dd5acd24308b0423bd9252e102b67 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Tue, 25 Feb 2020 14:28:39 +0100 Subject: [PATCH] Improved function behavior on empty matrices --- R/computeAllFreqs2.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/computeAllFreqs2.R b/R/computeAllFreqs2.R index 6ad2ca8..e3f68f8 100644 --- a/R/computeAllFreqs2.R +++ b/R/computeAllFreqs2.R @@ -6,7 +6,7 @@ #' @param SUMCOUNTS sumcounts #' @export computeAllFreqs2 <- function (noalle, COUNTS = matrix(NA, 0, 0), - SUMCOUNTS = sum(COUNTS)) { + SUMCOUNTS = NA) { max_noalle <- size(COUNTS, 1) nloci <- size(COUNTS,2) @@ -17,8 +17,10 @@ computeAllFreqs2 <- function (noalle, COUNTS = matrix(NA, 0, 0), sumCounts <- repmat(sumCounts, c(max_noalle, 1, 1)) prioriAlleelit <- zeros(max_noalle, nloci) - for (j in 1:nloci) { - prioriAlleelit[1:noalle[j], j] <- 1 / noalle[j] + if (nloci > 0) { + for (j in 1:nloci) { + prioriAlleelit[1:noalle[j], j] <- 1 / noalle[j] + } } prioriAlleelit <- repmat(prioriAlleelit, c(1, 1, npops)) counts <- COUNTS + prioriAlleelit