Skip to content

Commit

Permalink
Better robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jun 7, 2024
1 parent 7927c87 commit 5aafeda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ process_data <- function(data, model_variables = NULL) {
# Make sure integer inputs are of integer type to avoid
# generating a decimal point in write_stan_json
if (data_variables[[var_name]]$type == "int"
&& !(is.integer(data[[var_name]]) || all(data[[var_name]] == as.integer(data[[var_name]])))) {
warning("A non-integer value was supplied for '", var_name, "'!",
" It will be truncated to an integer.", call. = FALSE)
&& !is.integer(data[[var_name]])) {
if (!all(is_wholenumber(data[[var_name]]))) {
warning("A non-integer value was supplied for '", var_name, "'!",
" It will be truncated to an integer.", call. = FALSE)
}
mode(data[[var_name]]) <- "integer"
}
}
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ matching_variables <- function(variable_filters, variables) {
)
}

is_wholenumber <- function(x, tol = sqrt(.Machine$double.eps)) {
abs(x - round(x)) < tol
}

# checks for OS and hardware ----------------------------------------------

os_is_windows <- function() {
Expand Down

0 comments on commit 5aafeda

Please sign in to comment.