Skip to content

Commit d648cb5

Browse files
authored
Merge pull request #1222 from stan-dev/fix-compile-example
cleanly handle compiling with threads in compile doc
2 parents 4a3ddb8 + 839ede6 commit d648cb5

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

R/model.R

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,17 +533,23 @@ NULL
533533
#'
534534
#' @examples
535535
#' \dontrun{
536-
#' file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.stan")
536+
#' stan_file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.stan")
537537
#'
538538
#' # by default compilation happens when cmdstan_model() is called.
539539
#' # to delay compilation until calling the $compile() method set compile=FALSE
540-
#' mod <- cmdstan_model(file, compile = FALSE)
540+
#' mod <- cmdstan_model(stan_file, compile = FALSE)
541541
#' mod$compile()
542542
#' mod$exe_file()
543543
#'
544-
#' # turn on threading support (for using functions that support within-chain parallelization)
545-
#' mod$compile(force_recompile = TRUE, cpp_options = list(stan_threads = TRUE))
546-
#' mod$exe_file()
544+
#' # turn on threading support for using functions that support within-chain
545+
#' # parallelization or running multiple pathfinder paths in parallel
546+
#' # (here we compile a copy of the model in a temporary directory so that the
547+
#' # executable compiled without threading above is not overwritten)
548+
#' stan_file_threads <- file.path(tempdir(), "bernoulli.stan")
549+
#' file.copy(stan_file, stan_file_threads)
550+
#' mod_threads <- cmdstan_model(stan_file_threads, compile = FALSE)
551+
#' mod_threads$compile(cpp_options = list(stan_threads = TRUE))
552+
#' mod_threads$cpp_options()
547553
#'
548554
#' # turn on pedantic mode
549555
#' file_pedantic <- write_stan_file("
@@ -554,8 +560,9 @@ NULL
554560
#' sigma ~ exponential(1);
555561
#' }
556562
#' ")
557-
#' mod <- cmdstan_model(file_pedantic, pedantic = TRUE)
558-
#'
563+
#' mod <- cmdstan_model(file_pedantic, compile = FALSE)
564+
#' mod$compile(pedantic = TRUE)
565+
#' # same as mod <- cmdstan_model(file_pedantic, pedantic = TRUE)
559566
#' }
560567
#'
561568
compile <- function(quiet = TRUE,

man/model-method-compile.Rd

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)