@@ -63,6 +63,7 @@ These separate `.stan` files can then be accessed within the Stan code with the
6363
6464Generally speaking, there will be some function in an R package that will fit the data to a model.
6565In order to facilitate this fitting with a CmdStanR backend, a process like that below could be used.
66+ Note that this model assumes that cmdstanr is installed, though this could be replaced with other ways of calling Stan (e.g., ` rstan ` ).
6667
6768``` r
6869
@@ -73,22 +74,30 @@ fit_my_data <- function(my_data){
7374 if (length(list.files(local_location , pattern = " .stan" )) > 1 ) {
7475 cli :: cli_alert_info(" Using cached Stan models" )
7576 cli :: cli_alert_info(
76- " Use `intervalcalc::clear_cache ` if you need to refresh" )
77+ " Use `staninside::clear_stan_cache('mypackage') ` if you need to refresh" )
7778 } else {
7879 cli :: cli_alert_info(" Copying Stan models to cache" )
7980 staninside :: copy_models(this_pkg())
8081 cli :: cli_alert_success(" Models copied!" )
8182 }
8283
8384 model_file_path <- file.path(local_location , paste0(" base" , " .stan" ))
84- mod <- cmdstanr :: cmdstan_model(model_file_path )
85+ mod <- cmdstanr :: cmdstan_model(model_file_path )
8586
86- fit <- mod $ sample(data = my_data )
87+ fit <- mod $ sample(data = my_data )
8788
88- return (fit )
89+ return (fit )
8990}
9091
9192```
9293
94+ You now can call ` fit_my_data ` to fit your model.
95+ The underlying Stan code is stored in the user cache directory and will be compiled on the first model fitting operation.
96+
97+
98+
99+
100+
101+
93102
94103
0 commit comments