Skip to content

Commit

Permalink
Abbreviate code block with ifelse + vapply construct
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Funk <[email protected]>
  • Loading branch information
jamesmbaazam and sbfnk authored Sep 12, 2023
1 parent 0b2005a commit 5ab7c85
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions R/likelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,8 @@ likelihood <- function(chains, statistic = c("size", "length"), offspring_dist,
## (sum of the log-likelihoods), if log == TRUE, else
## multiply the likelihoods
if (isFALSE(individual)) {
if (isTRUE(log)) {
chains_likelihood <- vapply(chains_likelihood, sum, 0)
} else {
chains_likelihood <- vapply(chains_likelihood, prod, 0)
}
summarise_func <- ifelse(log, sum, prod)
vapply(chains_likelihood, summarise_func, 0)
}

return(chains_likelihood)
Expand Down

0 comments on commit 5ab7c85

Please sign in to comment.