@@ -233,7 +233,8 @@ CmdStanModel <- R6::R6Class(
233
233
precompile_cpp_options_ = NULL ,
234
234
precompile_stanc_options_ = NULL ,
235
235
precompile_include_paths_ = NULL ,
236
- variables_ = NULL
236
+ variables_ = NULL ,
237
+ cmdstan_version_ = NULL
237
238
),
238
239
public = list (
239
240
functions = NULL ,
@@ -271,8 +272,14 @@ CmdStanModel <- R6::R6Class(
271
272
if (! is.null(stan_file ) && compile ) {
272
273
self $ compile(... )
273
274
}
275
+
276
+ # for now, set this based on current version
277
+ # at initialize so its never null
278
+ # in the future, will be set only if/when we have a binary
279
+ # as the version the model was compiled with
280
+ private $ cmdstan_version_ <- cmdstan_version()
274
281
if (length(self $ exe_file()) > 0 && file.exists(self $ exe_file())) {
275
- cpp_options <- model_compile_info(self $ exe_file())
282
+ cpp_options <- model_compile_info(self $ exe_file(), self $ cmdstan_version() )
276
283
for (cpp_option_name in names(cpp_options )) {
277
284
if (cpp_option_name != " stan_version" &&
278
285
(! is.logical(cpp_options [[cpp_option_name ]]) || isTRUE(cpp_options [[cpp_option_name ]]))) {
@@ -328,6 +335,9 @@ CmdStanModel <- R6::R6Class(
328
335
}
329
336
private $ exe_file_
330
337
},
338
+ cmdstan_version = function () {
339
+ private $ cmdstan_version_
340
+ },
331
341
cpp_options = function () {
332
342
private $ cpp_options_
333
343
},
@@ -737,6 +747,7 @@ compile <- function(quiet = TRUE,
737
747
con = wsl_safe_path(private $ hpp_file_ , revert = TRUE ))
738
748
} # End - if(!dry_run)
739
749
750
+ private $ cmdstan_version_ <- cmdstan_version()
740
751
private $ exe_file_ <- exe
741
752
private $ cpp_options_ <- cpp_options
742
753
private $ precompile_cpp_options_ <- NULL
@@ -786,7 +797,7 @@ CmdStanModel$set("public", name = "compile", value = compile)
786
797
# ' }
787
798
# '
788
799
variables <- function () {
789
- if (cmdstan_version() < " 2.27.0" ) {
800
+ if (self $ cmdstan_version() < " 2.27.0" ) {
790
801
stop(" $variables() is only supported for CmdStan 2.27 or newer." , call. = FALSE )
791
802
}
792
803
if (length(self $ stan_file()) == 0 ) {
@@ -993,6 +1004,10 @@ format <- function(overwrite_file = FALSE,
993
1004
backup = TRUE ,
994
1005
max_line_length = NULL ,
995
1006
quiet = FALSE ) {
1007
+ # querying current version here not model object version
1008
+ # because this is pre-compile work based on the cmdstanr
1009
+ # version that will be used to compile in teh future,
1010
+ # not based on what was used to compile existing binary (if any)
996
1011
if (cmdstan_version() < " 2.29.0" && ! is.null(max_line_length )) {
997
1012
stop(
998
1013
" 'max_line_length' is only supported with CmdStan 2.29.0 or newer." ,
@@ -1208,7 +1223,7 @@ sample <- function(data = NULL,
1208
1223
}
1209
1224
}
1210
1225
1211
- if (cmdstan_version() > = " 2.27.0" && cmdstan_version() < " 2.36.0" && ! fixed_param ) {
1226
+ if (self $ cmdstan_version() > = " 2.27.0" && self $ cmdstan_version() < " 2.36.0" && ! fixed_param ) {
1212
1227
if (self $ has_stan_file() && file.exists(self $ stan_file())) {
1213
1228
if (! is.null(self $ variables()) && length(self $ variables()$ parameters ) == 0 ) {
1214
1229
stop(" Model contains no parameters. Please use 'fixed_param = TRUE'." , call. = FALSE )
@@ -1652,7 +1667,7 @@ laplace <- function(data = NULL,
1652
1667
show_messages = TRUE ,
1653
1668
show_exceptions = TRUE ,
1654
1669
save_cmdstan_config = NULL ) {
1655
- if (cmdstan_version() < " 2.32" ) {
1670
+ if (self $ cmdstan_version() < " 2.32" ) {
1656
1671
stop(" This method is only available in cmdstan >= 2.32" , call. = FALSE )
1657
1672
}
1658
1673
if (! is.null(mode ) && ! is.null(opt_args )) {
@@ -2382,9 +2397,9 @@ model_variables <- function(stan_file, include_paths = NULL, allow_undefined = F
2382
2397
variables
2383
2398
}
2384
2399
2385
- model_compile_info <- function (exe_file ) {
2400
+ model_compile_info <- function (exe_file , version ) {
2386
2401
info <- NULL
2387
- if (cmdstan_version() > " 2.26.1" ) {
2402
+ if (version > " 2.26.1" ) {
2388
2403
withr :: with_path(
2389
2404
c(
2390
2405
toolchain_PATH_env_var(),
0 commit comments