diff --git a/R/data.R b/R/data.R index 672d6058..a00e891f 100644 --- a/R/data.R +++ b/R/data.R @@ -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" } } diff --git a/R/utils.R b/R/utils.R index ef36d0c7..ecac323c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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() {