Skip to content

Commit 2ebf195

Browse files
authored
Merge pull request #823 from stan-dev/fix-example-errors
fix errors in doc for new methods
2 parents cea29b0 + b555aa6 commit 2ebf195

22 files changed

Lines changed: 209 additions & 154 deletions

R/example.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#' the individual methods for details.
2020
#' @param quiet (logical) If `TRUE` (the default) then fitting the model is
2121
#' wrapped in [utils::capture.output()].
22+
#' @param force_recompile Passed to the [$compile()][model-method-compile] method.
2223
#'
2324
#' @return
2425
#' The fitted model object returned by the selected `method`.
@@ -51,7 +52,8 @@ cmdstanr_example <-
5152
function(example = c("logistic", "schools", "schools_ncp"),
5253
method = c("sample", "optimize", "variational", "diagnose"),
5354
...,
54-
quiet = TRUE) {
55+
quiet = TRUE,
56+
force_recompile = getOption("cmdstanr_force_recompile", default = FALSE)) {
5557

5658
example <- match.arg(example)
5759
method <- match.arg(method)
@@ -63,7 +65,7 @@ cmdstanr_example <-
6365
if (!file.exists(tmp)) {
6466
file.copy(system.file(example_program, package = "cmdstanr"), tmp)
6567
}
66-
mod <- cmdstan_model(tmp)
68+
mod <- cmdstan_model(tmp, force_recompile = force_recompile)
6769
data_file <- system.file(example_data, package = "cmdstanr")
6870

6971
if (quiet) {

R/fit.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ CmdStanFit$set("public", name = "init", value = init)
324324
#'
325325
#' @examples
326326
#' \dontrun{
327-
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample")
327+
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
328328
#' fit_mcmc$init_model_methods()
329329
#' }
330330
#' @seealso [log_prob()], [grad_log_prob()], [constrain_variables()],
@@ -370,7 +370,7 @@ CmdStanFit$set("public", name = "init_model_methods", value = init_model_methods
370370
#'
371371
#' @examples
372372
#' \dontrun{
373-
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample")
373+
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
374374
#' fit_mcmc$init_model_methods()
375375
#' fit_mcmc$log_prob(unconstrained_variables = c(0.5, 1.2, 1.1, 2.2))
376376
#' }
@@ -408,7 +408,7 @@ CmdStanFit$set("public", name = "log_prob", value = log_prob)
408408
#'
409409
#' @examples
410410
#' \dontrun{
411-
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample")
411+
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
412412
#' fit_mcmc$init_model_methods()
413413
#' fit_mcmc$grad_log_prob(unconstrained_variables = c(0.5, 1.2, 1.1, 2.2))
414414
#' }
@@ -446,7 +446,7 @@ CmdStanFit$set("public", name = "grad_log_prob", value = grad_log_prob)
446446
#'
447447
#' @examples
448448
#' \dontrun{
449-
#' # fit_mcmc <- cmdstanr_example("logistic", method = "sample")
449+
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
450450
#' # fit_mcmc$init_model_methods(hessian = TRUE)
451451
#' # fit_mcmc$hessian(unconstrained_variables = c(0.5, 1.2, 1.1, 2.2))
452452
#' }
@@ -481,7 +481,7 @@ CmdStanFit$set("public", name = "hessian", value = hessian)
481481
#'
482482
#' @examples
483483
#' \dontrun{
484-
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample")
484+
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
485485
#' fit_mcmc$init_model_methods()
486486
#' fit_mcmc$unconstrain_variables(list(alpha = 0.5, beta = c(0.7, 1.1, 0.2)))
487487
#' }
@@ -539,7 +539,7 @@ CmdStanFit$set("public", name = "unconstrain_variables", value = unconstrain_var
539539
#'
540540
#' @examples
541541
#' \dontrun{
542-
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample")
542+
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
543543
#' fit_mcmc$init_model_methods()
544544
#'
545545
#' # Unconstrain all internal draws
@@ -618,7 +618,7 @@ CmdStanFit$set("public", name = "unconstrain_draws", value = unconstrain_draws)
618618
#'
619619
#' @examples
620620
#' \dontrun{
621-
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample")
621+
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
622622
#' fit_mcmc$init_model_methods()
623623
#' fit_mcmc$variable_skeleton()
624624
#' }
@@ -656,7 +656,7 @@ CmdStanFit$set("public", name = "variable_skeleton", value = variable_skeleton)
656656
#'
657657
#' @examples
658658
#' \dontrun{
659-
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample")
659+
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE)
660660
#' fit_mcmc$init_model_methods()
661661
#' fit_mcmc$constrain_variables(unconstrained_variables = c(0.5, 1.2, 1.1, 2.2))
662662
#' }

R/model.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ compile <- function(quiet = TRUE,
603603
wd = cmdstan_path(),
604604
echo = !quiet || is_verbose_mode(),
605605
echo_cmd = is_verbose_mode(),
606-
spinner = quiet && interactive(),
606+
spinner = quiet && interactive() && !identical(Sys.getenv("IN_PKGDOWN"), "true"),
607607
stderr_callback = function(x, p) {
608608
if (!startsWith(x, paste0(make_cmd(), ": *** No rule to make target"))) {
609609
message(x)

docs/reference/Rplot001.png

-3.93 KB
Loading

docs/reference/cmdstanr_example.html

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

docs/reference/fit-method-constrain_variables.html

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

0 commit comments

Comments
 (0)