Skip to content

Commit

Permalink
stopifnot to stopifnot_
Browse files Browse the repository at this point in the history
  • Loading branch information
helske committed Sep 4, 2024
1 parent e5eda39 commit e00dd6e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion R/estimate_coef.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param threads Number of threads to use in parallel computing.
#' The default is 1.
estimate_coef <- function(model, threads = 1) {
stopifnot(
stopifnot_(
inherits(model, "mhmm"),
"{.arg model} must be a {.cls mhmm} object."
)
Expand Down
8 changes: 5 additions & 3 deletions R/simulate_mnhmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ simulate_mnhmm <- function(
times <- sort(unique(data[[time]]))
clusters <- character(n_sequences)
cluster_names <- model$cluster_names
state_names <- paste0(rep(cluster_names, each = S), ": ", model$state_names)
state_names <- paste0(
rep(cluster_names, each = model$n_states), ": ", model$state_names
)
for (i in seq_len(n_sequences)) {
p_cluster <- probs$cluster[
probs$cluster[[time]] == time[1] & probs$cluster[[id]] == ids[i],
Expand All @@ -115,7 +117,7 @@ simulate_mnhmm <- function(
obs[1, k, i] <- sample(symbol_names[[k]], 1, prob = p_emission)
}
}

for (i in seq_len(n_sequences)) {
for (t in 2:sequence_lengths[i]) {
p_transition <- probs$transition[
Expand Down Expand Up @@ -147,7 +149,7 @@ simulate_mnhmm <- function(
obs <- lapply(seq_len(n_channels), function(i) {
suppressWarnings(suppressMessages(
seqdef(t(obs[, i, ]), alphabet = symbol_names[[i]])
))
))
})
names(obs) <- model$channel_names
if (n_channels == 1) obs <- obs[[1]]
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-estimate_coef.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

test_that("'estimate_coef' works for 'mhmm'", {
set.seed(123)
data("mhmm_biofam")
expect_error(
out <- estimate_coef(mhmm_biofam),
NA
Expand All @@ -10,13 +11,14 @@ test_that("'estimate_coef' works for 'mhmm'", {

test_that("'estimate_coef' errors for 'hmm'", {
set.seed(123)
data("hmm_biofam")
expect_error(
out <- estimate_coef(hmm_biofam),
"`model` must be a `mhmm` object."
)
})
test_that("'estimate_coef' errors for incorrect 'threads'", {
set.seed(123)
data("mhmm_biofam")
expect_error(
out <- estimate_coef(mhmm_biofam, threads = "a"),
"Argument `threads` must be a single positive integer"
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-fit_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test_that("'fit_model' works for 'hmm'", {
),
NA
)
expect_error(print(fit$model), NA)
})

test_that("'fit_model' works for 'mhmm'", {
Expand Down Expand Up @@ -94,5 +93,4 @@ test_that("'fit_model' works for 'mhmm'", {
),
NA
)
expect_error(print(fit$model), NA)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-forward_backward.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test_that("'forward_backward' works for multichannel 'nhmm'", {
)
expect_gte(min(fb$forward_probs), -200)
expect_gte(min(fb$backward_probs), -200)
expect_lte(max(fb$forward_probs), -5)
expect_lte(max(fb$forward_probs), 0)
expect_lte(max(fb$backward_probs), 0)

expect_error(
Expand Down

0 comments on commit e00dd6e

Please sign in to comment.