Skip to content

Commit 11f2585

Browse files
committed
fix handling integers
1 parent ea5bc44 commit 11f2585

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

R/data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ process_data <- function(data, model_variables = NULL) {
186186
# generating a decimal point in write_stan_json
187187
if (data_variables[[var_name]]$type == "int"
188188
&& !is.integer(data[[var_name]])) {
189-
data[[var_name]] <- as.integer(data[[var_name]])
189+
mode(data[[var_name]]) <- "integer"
190190
}
191191
}
192192
}

tests/testthat/test-data.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,23 @@ test_that("process_data() corrrectly casts integers and floating point numbers",
337337
readLines(test_file)[3],
338338
fixed = TRUE
339339
)
340+
341+
stan_file <- write_stan_file("
342+
data {
343+
int<lower=0> k[3,3];
344+
}
345+
")
346+
mod <- cmdstan_model(stan_file, compile = FALSE)
347+
test_file <- process_data(list(k = matrix(c(18, 18, 16, 13, 9, 6, 4, 4, 4), nrow=3, ncol=3, byrow=T)), model_variables = mod$variables())
348+
print(readLines(test_file)[2:3])
349+
expect_match(
350+
" \"k\": [",
351+
readLines(test_file)[2],
352+
fixed = TRUE
353+
)
354+
expect_match(
355+
" [18, 18, 16],",
356+
readLines(test_file)[3],
357+
fixed = TRUE
358+
)
340359
})

0 commit comments

Comments
 (0)