Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document global options and add cmdstanr_output_dir #951

Merged
merged 7 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ URL: https://mc-stan.org/cmdstanr/, https://discourse.mc-stan.org
BugReports: https://github.com/stan-dev/cmdstanr/issues
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE, r6 = FALSE)
SystemRequirements: CmdStan (https://mc-stan.org/users/interfaces/cmdstan)
Depends:
Expand Down
3 changes: 3 additions & 0 deletions R/cmdstanr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#' [_Getting started with CmdStanR_](https://mc-stan.org/cmdstanr/articles/cmdstanr.html)
#' demonstrates the basic functionality of the package.
#'
#' For a list of global [options][base::options()] see
#' [cmdstanr_global_options].
#'
#' @template seealso-docs
#' @inherit cmdstan_model examples
#' @import R6
Expand Down
7 changes: 3 additions & 4 deletions R/generics.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

#' Coercion methods for CmdStan objects
#'
#' These methods are used to coerce objects into `cmdstanr` objects.
#' Primarily intended for other packages to use when interfacing
#' with `cmdstanr`.
#' These are generic functions intended to primarily be used by developers of
#' packages that interface with on CmdStanR. Developers can define methods on
#' top of these generics to coerce objects into CmdStanR's fitted model objects.
#'
#' @param object to be coerced
#' @param ... additional arguments
Expand Down
16 changes: 8 additions & 8 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ sample <- function(data = NULL,
refresh = NULL,
init = NULL,
save_latent_dynamics = FALSE,
output_dir = NULL,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
sig_figs = NULL,
chains = 4,
Expand Down Expand Up @@ -1334,7 +1334,7 @@ sample_mpi <- function(data = NULL,
refresh = NULL,
init = NULL,
save_latent_dynamics = FALSE,
output_dir = NULL,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
chains = 1,
chain_ids = seq_len(chains),
Expand Down Expand Up @@ -1484,7 +1484,7 @@ optimize <- function(data = NULL,
refresh = NULL,
init = NULL,
save_latent_dynamics = FALSE,
output_dir = NULL,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
sig_figs = NULL,
threads = NULL,
Expand Down Expand Up @@ -1622,7 +1622,7 @@ laplace <- function(data = NULL,
refresh = NULL,
init = NULL,
save_latent_dynamics = FALSE,
output_dir = NULL,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
sig_figs = NULL,
threads = NULL,
Expand Down Expand Up @@ -1769,7 +1769,7 @@ variational <- function(data = NULL,
refresh = NULL,
init = NULL,
save_latent_dynamics = FALSE,
output_dir = NULL,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
sig_figs = NULL,
threads = NULL,
Expand Down Expand Up @@ -1908,7 +1908,7 @@ pathfinder <- function(data = NULL,
refresh = NULL,
init = NULL,
save_latent_dynamics = FALSE,
output_dir = NULL,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
sig_figs = NULL,
opencl_ids = NULL,
Expand Down Expand Up @@ -2060,7 +2060,7 @@ CmdStanModel$set("public", name = "pathfinder", value = pathfinder)
generate_quantities <- function(fitted_params,
data = NULL,
seed = NULL,
output_dir = NULL,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
sig_figs = NULL,
parallel_chains = getOption("mc.cores", 1),
Expand Down Expand Up @@ -2125,7 +2125,7 @@ CmdStanModel$set("public", name = "generate_quantities", value = generate_quanti
diagnose <- function(data = NULL,
seed = NULL,
init = NULL,
output_dir = NULL,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
epsilon = NULL,
error = NULL) {
Expand Down
42 changes: 42 additions & 0 deletions R/options.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' CmdStanR global options
#'
#' These options can be set via [options()] for an entire \R session.
#'
#' @name cmdstanr_global_options
#'
#' @details
#'
#' * `cmdstanr_draws_format`: Which format provided by the \pkg{posterior}
#' package should be used when returning the posterior or approximate posterior
#' draws? The default depends on the model fitting method. See
#' [draws][fit-method-draws] for more details.
#'
#' * `cmdstanr_force_recompile`: Should the default be to recompile models
#' even if there were no Stan code changes since last compiled? See
#' [compile][model-method-compile] for more details. The default is `FALSE`.
#'
#' * `cmdstanr_max_rows`: The maximum number of rows of output to print when
#' using the [`$print()`][fit-method-summary] method. The default is 10.
#'
#' * `cmdstanr_no_ver_check`: Should the check for a more recent version of
#' CmdStan be disabled? The default is `FALSE`.
#'
#' * `cmdstanr_output_dir`: The directory where CmdStan should write its output
#' CSV files when fitting models. The default is a temporary directory.
jgabry marked this conversation as resolved.
Show resolved Hide resolved
#'
#' * `cmdstanr_verbose`: Should more information be printed
#' when compiling or running models, including showing how CmdStan was called
#' internally? The default is `FALSE`.
#'
#' * `cmdstanr_warn_inits`: Should a warning be thrown if initial values are
#' only provided for a subset of parameters? The default is `TRUE`.
#'
#' * `cmdstanr_write_stan_file_dir`: The directory where [write_stan_file()]
#' should write Stan files. The default is a temporary directory.
jgabry marked this conversation as resolved.
Show resolved Hide resolved
#'
#' * `mc.cores`: The number of cores to use for various parallelization tasks
#' (e.g. running MCMC chains, installing CmdStan). The default depends on the
#' use case and is documented with the methods that make use of `mc.cores`.
#'
#'
NULL
13 changes: 10 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ startup_messages <- function() {
}

skip_version_check <- isTRUE(getOption(
"CMDSTANR_NO_VER_CHECK",
default = identical(tolower(Sys.getenv("CMDSTANR_NO_VER_CHECK")), "true")
"cmdstanr_no_ver_check",
default = identical(tolower(Sys.getenv("cmdstanr_no_ver_check")), "true")
))
if (!skip_version_check) {
# check if they used the old all caps version
skip_version_check <- isTRUE(getOption(
"CMDSTANR_NO_VER_CHECK",
default = identical(tolower(Sys.getenv("CMDSTANR_NO_VER_CHECK")), "true")
))
}
if (!skip_version_check) {
latest_version <- try(suppressWarnings(latest_released_version(retries = 0)), silent = TRUE)
current_version <- try(cmdstan_version(), silent = TRUE)
Expand All @@ -21,7 +28,7 @@ startup_messages <- function() {
&& latest_version > current_version) {
packageStartupMessage(
"\nA newer version of CmdStan is available. See ?install_cmdstan() to install it.",
"\nTo disable this check set option or environment variable CMDSTANR_NO_VER_CHECK=TRUE."
"\nTo disable this check set option or environment variable cmdstanr_no_ver_check=TRUE."
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion man-roxygen/model-common-args.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
#' methods there will be a single file. For interactive use this can typically
#' be left at `NULL` (temporary directory) since CmdStanR makes the CmdStan
#' output (posterior draws and diagnostics) available in \R via methods of the
#' fitted model objects. The behavior of `output_dir` is as follows:
#' fitted model objects. This can be set for an entire \R session using
#' `options(cmdstanr_output_dir)`. The behavior of `output_dir` is as follows:
#' * If `NULL` (the default), then the CSV files are written to a temporary
#' directory and only saved permanently if the user calls one of the `$save_*`
#' methods of the fitted model object (e.g.,
Expand Down
6 changes: 3 additions & 3 deletions man/cmdstan_coercion.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/cmdstanr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions man/cmdstanr_global_options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/model-method-check_syntax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/model-method-compile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/model-method-diagnose.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/model-method-expose_functions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/model-method-format.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/model-method-generate-quantities.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/model-method-laplace.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/model-method-optimize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading