diff --git a/R/csv.R b/R/csv.R index 5adbdd66..4e585fa6 100644 --- a/R/csv.R +++ b/R/csv.R @@ -719,7 +719,7 @@ read_csv_metadata <- function(csv_file) { dense_inv_metric <- TRUE } else if (inv_metric_next) { inv_metric_split <- strsplit(gsub("# ", "", line), ",") - numeric_inv_metric_split <- rapply(inv_metric_split, as.numeric) + numeric_inv_metric_split <- suppressWarnings(rapply(inv_metric_split, as.numeric)) if (inv_metric_rows == -1 && dense_inv_metric) { inv_metric_rows <- length(inv_metric_split[[1]]) inv_metric_rows_to_read <- inv_metric_rows @@ -786,6 +786,7 @@ read_csv_metadata <- function(csv_file) { } } if (csv_file_info$method != "diagnose" && + !isTRUE(csv_file_info$algorithm == "fixed_param") && length(csv_file_info$sampler_diagnostics) == 0 && length(csv_file_info$variables) == 0) { stop("Supplied CSV file does not contain any variable names or data!", call. = FALSE) diff --git a/R/model.R b/R/model.R index e17ffbd4..e11603fd 100644 --- a/R/model.R +++ b/R/model.R @@ -1208,7 +1208,7 @@ sample <- function(data = NULL, } } - if (cmdstan_version() >= "2.27.0" && !fixed_param) { + if (cmdstan_version() >= "2.27.0" && cmdstan_version() < "2.36.0" && !fixed_param) { if (self$has_stan_file() && file.exists(self$stan_file())) { if (!is.null(self$variables()) && length(self$variables()$parameters) == 0) { stop("Model contains no parameters. Please use 'fixed_param = TRUE'.", call. = FALSE) diff --git a/tests/testthat/test-model-sample.R b/tests/testthat/test-model-sample.R index 8afe3053..d0ed29a1 100644 --- a/tests/testthat/test-model-sample.R +++ b/tests/testthat/test-model-sample.R @@ -307,7 +307,7 @@ test_that("seed works for multi chain sampling", { expect_false(all(chain_tdata_1 == chain_tdata_2)) }) -test_that("fixed_param is set when the model has no parameters", { +test_that("Correct behavior if fixed_param not set when the model has no parameters", { code <- " model {} generated quantities { @@ -316,10 +316,21 @@ test_that("fixed_param is set when the model has no parameters", { " stan_file <- write_stan_file(code) m <- cmdstan_model(stan_file) + fake_cmdstan_version("2.35.0") expect_error( m$sample(), "Model contains no parameters. Please use 'fixed_param = TRUE'." ) + + reset_cmdstan_version() + if (cmdstan_version() >= "2.36.0") { + # as of 2.36.0 we don't need fixed_param if no parameters + expect_no_error( + utils::capture.output( + fit <- m$sample(iter_warmup = 10, iter_sampling = 10, diagnostics = NULL) + ) + ) + } }) test_that("sig_figs warning if version less than 2.25", {