Skip to content

Commit

Permalink
Update error messages about variable types
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Claessens authored and Scott Claessens committed Sep 9, 2024
1 parent f631520 commit 45fa830
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
12 changes: 8 additions & 4 deletions R/coev_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ run_checks <- function(data, variables, id, tree, effects_mat,
stop2(
paste0(
"Variables following the 'bernoulli_logit' response distribution ",
"must be integers with values of 0/1 in the data."
"must be integers with values of 0/1 in the data. Try using the ",
"as.integer() function to convert variables to integers."
)
)
}
Expand All @@ -58,7 +59,8 @@ run_checks <- function(data, variables, id, tree, effects_mat,
stop2(
paste0(
"Variables following the 'ordered_logistic' response distribution ",
"must be ordered factors in the data."
"must be ordered factors in the data. Try using the as.ordered() ",
"function to convert variables to ordered factors."
)
)
}
Expand All @@ -72,7 +74,8 @@ run_checks <- function(data, variables, id, tree, effects_mat,
stop2(
paste0(
"Variables following the 'poisson_softplus' response distribution ",
"must be integers greater than or equal to zero in the data."
"must be integers greater than or equal to zero in the data. Try ",
"using the as.integer() function to convert variables to integers."
)
)
}
Expand All @@ -84,7 +87,8 @@ run_checks <- function(data, variables, id, tree, effects_mat,
paste0(
"Variables following the 'negative_binomial_softplus' response ",
"distribution must be integers greater than or equal to zero in ",
"the data."
"the data. Try using the as.integer() function to convert variables ",
"to integers."
)
)
}
Expand Down
24 changes: 16 additions & 8 deletions tests/testthat/test-coev_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ test_that("coev_fit() produces expected errors", {
),
paste0(
"Variables following the 'bernoulli_logit' response distribution ",
"must be integers with values of 0/1 in the data."
)
"must be integers with values of 0/1 in the data. Try using the ",
"as.integer() function to convert variables to integers."
),
fixed = TRUE
)
expect_error(
coev_fit(
Expand All @@ -114,8 +116,10 @@ test_that("coev_fit() produces expected errors", {
),
paste0(
"Variables following the 'ordered_logistic' response distribution ",
"must be ordered factors in the data."
)
"must be ordered factors in the data. Try using the as.ordered() ",
"function to convert variables to ordered factors."
),
fixed = TRUE
)
expect_error(
coev_fit(
Expand All @@ -129,8 +133,10 @@ test_that("coev_fit() produces expected errors", {
),
paste0(
"Variables following the 'poisson_softplus' response distribution ",
"must be integers greater than or equal to zero in the data."
)
"must be integers greater than or equal to zero in the data. Try ",
"using the as.integer() function to convert variables to integers."
),
fixed = TRUE
)
expect_error(
coev_fit(
Expand All @@ -145,8 +151,10 @@ test_that("coev_fit() produces expected errors", {
paste0(
"Variables following the 'negative_binomial_softplus' response ",
"distribution must be integers greater than or equal to zero in ",
"the data."
)
"the data. Try using the as.integer() function to convert variables ",
"to integers."
),
fixed = TRUE
)
expect_error(
coev_make_stancode(
Expand Down
24 changes: 16 additions & 8 deletions tests/testthat/test-coev_make_stancode.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ test_that("coev_make_stancode() produces expected errors", {
),
paste0(
"Variables following the 'bernoulli_logit' response distribution ",
"must be integers with values of 0/1 in the data."
)
"must be integers with values of 0/1 in the data. Try using the ",
"as.integer() function to convert variables to integers."
),
fixed = TRUE
)
expect_error(
coev_make_stancode(
Expand All @@ -114,8 +116,10 @@ test_that("coev_make_stancode() produces expected errors", {
),
paste0(
"Variables following the 'ordered_logistic' response distribution ",
"must be ordered factors in the data."
)
"must be ordered factors in the data. Try using the as.ordered() ",
"function to convert variables to ordered factors."
),
fixed = TRUE
)
expect_error(
coev_make_stancode(
Expand All @@ -129,8 +133,10 @@ test_that("coev_make_stancode() produces expected errors", {
),
paste0(
"Variables following the 'poisson_softplus' response distribution ",
"must be integers greater than or equal to zero in the data."
)
"must be integers greater than or equal to zero in the data. Try ",
"using the as.integer() function to convert variables to integers."
),
fixed = TRUE
)
expect_error(
coev_make_stancode(
Expand All @@ -145,8 +151,10 @@ test_that("coev_make_stancode() produces expected errors", {
paste0(
"Variables following the 'negative_binomial_softplus' response ",
"distribution must be integers greater than or equal to zero in ",
"the data."
)
"the data. Try using the as.integer() function to convert variables ",
"to integers."
),
fixed = TRUE
)
expect_error(
coev_make_stancode(
Expand Down
24 changes: 16 additions & 8 deletions tests/testthat/test-coev_make_standata.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ test_that("coev_make_standata() produces expected errors", {
),
paste0(
"Variables following the 'bernoulli_logit' response distribution ",
"must be integers with values of 0/1 in the data."
)
"must be integers with values of 0/1 in the data. Try using the ",
"as.integer() function to convert variables to integers."
),
fixed = TRUE
)
expect_error(
coev_make_standata(
Expand All @@ -114,8 +116,10 @@ test_that("coev_make_standata() produces expected errors", {
),
paste0(
"Variables following the 'ordered_logistic' response distribution ",
"must be ordered factors in the data."
)
"must be ordered factors in the data. Try using the as.ordered() ",
"function to convert variables to ordered factors."
),
fixed = TRUE
)
expect_error(
coev_make_standata(
Expand All @@ -129,8 +133,10 @@ test_that("coev_make_standata() produces expected errors", {
),
paste0(
"Variables following the 'poisson_softplus' response distribution ",
"must be integers greater than or equal to zero in the data."
)
"must be integers greater than or equal to zero in the data. Try ",
"using the as.integer() function to convert variables to integers."
),
fixed = TRUE
)
expect_error(
coev_make_standata(
Expand All @@ -145,8 +151,10 @@ test_that("coev_make_standata() produces expected errors", {
paste0(
"Variables following the 'negative_binomial_softplus' response ",
"distribution must be integers greater than or equal to zero in ",
"the data."
)
"the data. Try using the as.integer() function to convert variables ",
"to integers."
),
fixed = TRUE
)
expect_error(
coev_make_stancode(
Expand Down

0 comments on commit 45fa830

Please sign in to comment.