From cb54aee74183b54b31a61b8cd2e9b3a93bea26cc Mon Sep 17 00:00:00 2001 From: jgabry Date: Thu, 24 Sep 2026 15:33:27 -0600 Subject: [PATCH 1/2] Tidy the prose added for v1.0 A read of everything the v1.0 branch adds to NEWS, the roxygen and the internals vignette, done before the release candidate. Most of the changes make make and stanc bare lowercase words in prose, which the new text spelled three ways; backticks stay only for code the reader types or reads, such as `make/local` or `STANCFLAGS`. Two errors in R/cpp_options.R now quote argument names with backticks like the rest of the new errors, an error in R/build.R no longer reads "executable executable", and a handful of roxygen paragraphs and vignette sentences are shortened or split. The tests that match the changed error text are updated to the new wording. Part of #1258. --- NEWS.md | 12 +++++----- R/build.R | 5 +++- R/build_record.R | 36 ++++++++++++++--------------- R/cpp_options.R | 20 ++++++++-------- R/model.R | 20 ++++++++-------- R/path.R | 9 ++++---- R/run.R | 22 ++++++++---------- R/stanc.R | 32 ++++++++++++------------- R/utils.R | 9 ++++---- man/cmdstan_model.Rd | 4 ++-- man/model-method-build_info.Rd | 12 +++++----- man/model-method-model-info.Rd | 2 +- man/stan_build_info.Rd | 32 ++++++++++++------------- tests/testthat/test-cpp-options.R | 14 +++++------ tests/testthat/test-model-compile.R | 4 ++-- tests/testthat/test-opencl.R | 8 +++---- vignettes/cmdstanr-internals.Rmd | 20 ++++++++-------- 17 files changed, 132 insertions(+), 129 deletions(-) diff --git a/NEWS.md b/NEWS.md index d1ab610ca..04e80af73 100644 --- a/NEWS.md +++ b/NEWS.md @@ -78,7 +78,7 @@ spelled as make variables: `list(stan_threads = TRUE)` comes back as * Every `cpp_options` entry must now be named, with a make variable name. An unnamed entry gets an error saying where it belongs: `list(NAME = value)` for a plain assignment, `cmdstan_make_local()` for `+=` and the other makefile -operators. Previously unnamed entries reached `make` but nothing else saw them. +operators. Previously unnamed entries reached make but nothing else saw them. (#1250) * `cpp_options = list(stan_threads = FALSE)` now turns threading off, even when `make/local` turns it on, and the same holds for `FALSE` on any option. @@ -107,14 +107,14 @@ error that points at the right argument. (#1258) `STANCFLAGS`. (#1258) * Named `stanc_options` values such as `list(canonicalize = "deprecations")` and numeric ones such as `list("max-line-length" = 78)` now work. Previously the -named values reached `stanc` shell-quoted, which it rejected, and the numeric +named values reached stanc shell-quoted, which it rejected, and the numeric ones were dropped. (#1227, #1233) -* A `stanc` error now stops the build immediately and shows `stanc`'s message. +* A stanc error now stops the build immediately and shows stanc's message. Previously it surfaced several steps later. (#1227) * An include path that does not exist is now reported by its absolute path. (#1227) * `$include_paths()` now returns absolute paths, resolved when the model is -created. Previously a relative include path was resolved on every `stanc` call, +created. Previously a relative include path was resolved on every stanc call, so changing the working directory could point `#include` at the wrong directory. (#1229) * `#include` directories with spaces in their paths now work. (#820, #1230) @@ -229,7 +229,7 @@ not created and keeps saved metric files after the fitted model is garbage-collected. (#1021) * `cmdstan_model()` no longer fails when `MAKEFLAGS` turns on directory printing. (#1163) -* Quoted values in `make/local`'s `STANCFLAGS` now reach `stanc` as one +* Quoted values in `make/local`'s `STANCFLAGS` now reach stanc as one argument. Previously they were split on whitespace. (#1232) * `laplace()` no longer overwrites the internally generated optimizer CSV when `mode = NULL` and `output_basename` is supplied. The internally generated @@ -243,7 +243,7 @@ was always 1. (#1187) * `$lp_approx()` and `$mle()` now return numeric vectors whatever the `cmdstanr_draws_format` option is set to. (#1190) * A Stan file name with several spaces, or quotes, now gives a valid model name -for `stanc`. Previously only the first space was replaced and the quotes ended +for stanc. Previously only the first space was replaced and the quotes ended up in the generated C++. (#1200) * `$draws()` on a pathfinder fit now orders the diagnostic columns the same way as the other methods. (#1205) diff --git a/R/build.R b/R/build.R index 51dbb03ce..0480a668c 100644 --- a/R/build.R +++ b/R/build.R @@ -253,7 +253,10 @@ install_executable <- function(from, to, record) { error_on_status = FALSE ) if (is.na(chmod$status) || chmod$status != 0) { - stop("Could not make the compiled executable executable.", call. = FALSE) + stop( + "Could not set the execute bit on the compiled executable.", + call. = FALSE + ) } } write_build_record(record, candidate) diff --git a/R/build_record.R b/R/build_record.R index 47501fae4..15f5b6caa 100644 --- a/R/build_record.R +++ b/R/build_record.R @@ -157,7 +157,7 @@ validate_build_record <- function(record) { option_name <- names(cpp_options)[[i]] field <- paste0("configuration.cpp_options.", option_name) if (!grepl(paste0("^", make_variable_name_pattern, "$"), option_name)) { - stop_build_record_field(field, "must be named for a Make variable") + stop_build_record_field(field, "must be named for a make variable") } assert_record_shape(cpp_options[[i]], "string", field) } @@ -252,7 +252,7 @@ validate_build_record <- function(record) { #' The one place a record is built. The fields go in the schema's order so the #' written JSON reads that way too. #' -#' @param configuration The options the build used: `cpp_options` as the Make +#' @param configuration The options the build used: `cpp_options` as the make #' assignments `parsed_cpp_options()` returns, one per name; `stanc_options`, #' `stanc_options_added` and `stanc_options_from_make` as the argument #' vectors stanc receives; `stanc_name`; and `include_paths` as searched. @@ -681,7 +681,7 @@ assess_build <- function(expected, current) { #' When the build record is available, there are four more fields: #' #' * `configuration`: A list of the options the model was created with. -#' * `cpp_options`: the list of options in their Make spelling, as +#' * `cpp_options`: the list of options in their make spelling, as #' `$cpp_options()` reports them. For example, `list(stan_threads = TRUE)` #' comes back as `list(STAN_THREADS = "true")`. #' * `stanc_options`: the flags as given to stanc, in order. @@ -694,14 +694,14 @@ assess_build <- function(expected, current) { #' included files. When none were provided but the Stan program has includes #' this is set to the program's own directory. #' -#' * `dependencies`: A list describing the files the build read. Contains sublists -#' `stan_file`, `included_files`, `user_header` and `make_local`. `user_header` -#' and `make_local` are `NULL` when the build had none. `included_files` holds -#' one entry per file. Each entry has two fields: `built_from`, the path the -#' file had when the build ran, and `exists`, whether that path exists now. A -#' path that no longer exists is not necessarily a problem. For example, an \R -#' package may build its models at install time in a temporary directory that -#' is gone by the time the model is used. +#' * `dependencies`: A list describing the files the build read. Contains +#' sublists `stan_file`, `included_files`, `user_header` and `make_local`. +#' `user_header` and `make_local` are `NULL` when the build had none. +#' `included_files` holds one entry per file. Each entry has two fields: +#' `built_from`, the path the file had when the build ran, and `exists`, whether +#' that path exists now. A path that no longer exists is not necessarily a +#' problem. For example, an \R package may build its models at install time in a +#' temporary directory that is gone by the time the model is used. #' #' * `cmdstan`: A list containing the `path` and `version` of the CmdStan #' installation that built the executable, and whether that path still `exists`. @@ -710,13 +710,13 @@ assess_build <- function(expected, current) { #' release-candidate suffix whereas `reported_features$stan_version` comes from #' the Stan library headers the executable was compiled against and will not). #' -#' * `untracked_dependencies`: A list of files the build depended on that CmdStanR -#' cannot follow, so a change to them does not automatically trigger a rebuild. -#' An empty list means nothing of the kind was found. Each file is reported as -#' a sublist with two fields: `kind`, which is `"make_local_include"` when -#' `make/local` includes another makefile or `"user_header_include"` when the -#' user header includes other headers, and `detected_in`, the file the include -#' was found in. +#' * `untracked_dependencies`: A list of files the build depended on that +#' CmdStanR cannot follow, so a change to them does not automatically trigger a +#' rebuild. An empty list means nothing of the kind was found. Each file is +#' reported as a sublist with two fields: `kind`, which is +#' `"make_local_include"` when `make/local` includes another makefile or +#' `"user_header_include"` when the user header includes other headers, and +#' `detected_in`, the file the include was found in. #' #' The result leaves out some of what the record holds: the file hashes the #' rebuild check compares, the stanc flags CmdStanR added itself, the model diff --git a/R/cpp_options.R b/R/cpp_options.R index cb2154778..15a6f9da6 100644 --- a/R/cpp_options.R +++ b/R/cpp_options.R @@ -7,7 +7,7 @@ #' #' @param cpp_options The user's `cpp_options`, as #' `assert_valid_cpp_options()` returned them. -#' @return A named list with one value per Make variable. +#' @return A named list with one value per make variable. #' @noRd parsed_cpp_options <- function(cpp_options) { assignments <- structure(list(), names = character()) @@ -46,7 +46,7 @@ make_variable_name_pattern <- "[A-Za-z_][A-Za-z0-9_]*" #' Check the `cpp_options` the user supplied and return them #' -#' Every entry must be named and every name must be a Make variable name. The +#' Every entry must be named and every name must be a make variable name. The #' names are uppercased here so that one spelling reaches everything downstream. #' The user header and the stanc flags have their own arguments, so setting them #' here is an error. A TBB directory has to be a literal path, since the build @@ -68,7 +68,7 @@ assert_valid_cpp_options <- function(cpp_options) { } if (!grepl(paste0("^", make_variable_name_pattern, "$"), option_names[[i]])) { stop( - "`cpp_options` names must be Make variable names, made of letters, ", + "`cpp_options` names must be make variable names, made of letters, ", "digits and underscores and not starting with a digit. `", option_names[[i]], "` is not one.", call. = FALSE @@ -155,7 +155,7 @@ unnamed_cpp_option_message <- function(value) { if (grepl("^(-B|--always-make)$", entry)) { return(sprintf( paste0( - "Make flags cannot be passed through `cpp_options`. ", + "`cpp_options` cannot pass flags to make. ", "`%s` rebuilds everything; pass `force_recompile = TRUE` instead." ), entry @@ -166,7 +166,7 @@ unnamed_cpp_option_message <- function(value) { path <- sub(makefile_flag_pattern, "\\1", entry) return(sprintf( paste0( - "Make flags cannot be passed through `cpp_options`. ", + "`cpp_options` cannot pass flags to make. ", "To read another makefile add `include %s` to `make/local`, for example ", "`cmdstan_make_local(cpp_options = list(%s))`." ), @@ -175,7 +175,7 @@ unnamed_cpp_option_message <- function(value) { } if (startsWith(entry, "-")) { return(paste0( - "Make flags cannot be passed through `cpp_options`. ", + "`cpp_options` cannot pass flags to make. ", "Set them in `make/local` with `cmdstan_make_local()`, ", "for example `MAKEFLAGS += -j4`." )) @@ -240,9 +240,9 @@ assert_valid_threads <- function(threads, features, multiple_chains = FALSE) { threaded <- isTRUE(features[["stan_threads"]]) if (!is.null(threads) && threads > 1 && !threaded) { stop( - "'", threads_arg, "' is set but the executable does not report ", + "`", threads_arg, "` is set but the executable does not report ", "threading as enabled.\nRecompile the model with ", - "'cpp_options = list(stan_threads = TRUE)'.", + "`cpp_options = list(stan_threads = TRUE)`.", call. = FALSE ) } @@ -258,9 +258,9 @@ assert_valid_threads <- function(threads, features, multiple_chains = FALSE) { assert_valid_opencl <- function(opencl_ids, features) { if (!is.null(opencl_ids) && !isTRUE(features[["stan_opencl"]])) { stop( - "'opencl_ids' is set but the executable does not report OpenCL as ", + "`opencl_ids` is set but the executable does not report OpenCL as ", "enabled.\nRecompile the model with ", - "'cpp_options = list(stan_opencl = TRUE)'.", + "`cpp_options = list(stan_opencl = TRUE)`.", call. = FALSE ) } diff --git a/R/model.R b/R/model.R index ae7fe451a..acef372cd 100644 --- a/R/model.R +++ b/R/model.R @@ -55,7 +55,7 @@ #' model (`stan_threads`, `stan_mpi`, `stan_opencl`, etc.), written as #' `list(NAME = value)`. Each entry is an assignment you could make in the #' `make/local` file, so `list(CXXFLAGS = "-O3")` rather than `"-O3"`. -#' Every entry must be named with a `Make` variable name, in any casing. +#' Every entry must be named with a make variable name, in any casing. #' Setting an option to `FALSE` or `NULL` passes an empty assignment such as #' `STAN_THREADS=`. That empties the variable for this build, which turns a #' switch off, and overrides whatever `make/local` sets. See @@ -68,7 +68,7 @@ #' when compiling the model. A flag is given by name without the leading #' hyphens, as `list("O1")` or `list(O1 = TRUE)`, and an option that takes a #' value as `list(option = "value")`. See [stan_build_info()] for an example -#' and the [`stanc` chapter of the CmdStan User's +#' and the [stanc chapter of the CmdStan User's #' Guide](https://mc-stan.org/docs/cmdstan-guide/stanc.html) for the #' available options. Options that CmdStanR sets from its own arguments #' cannot be passed here: `include-paths` (use `include_paths`), @@ -596,7 +596,7 @@ CmdStanModel <- R6::R6Class( #' * `$cmdstan_version()` returns the version of CmdStan that built the #' executable, as a string. #' * `$cpp_options()` returns a named list of C++ options, with names in their -#' `make` spelling. +#' make spelling. #' * `$user_header()` returns the absolute path to the user header as a string, #' or `NULL` if the model has no user header. #' * `$hpp_file()` returns the path to the `.hpp` file holding the C++ code @@ -2191,14 +2191,14 @@ CmdStanModel$set("public", name = "cmdstan_defaults", value = cmdstan_defaults) #' now, so it also works on a model whose executable was replaced or whose #' build record is gone. #' -#' This method is different than the `$cpp_options()` method, which answers a +#' This method is different from the `$cpp_options()` method, which answers a #' narrower question: the C++ options this model object was created with. #' `$build_info()` describes the executable itself, including what it reports -#' about its own build when run. The difference is clear when considering a -#' model created with `cmdstan_model(exe_file = )` from just an executable -#' with no build record: `$cpp_options()` is empty, since no options were -#' given, but `$build_info()` still reports whether the executable was built -#' with threading, OpenCL and so on. +#' about its own build when run. Take a model created with +#' `cmdstan_model(exe_file = )` from an executable with no build record: +#' `$cpp_options()` is empty, since no options were given, but `$build_info()` +#' still reports whether the executable was built with threading, OpenCL and +#' so on. #' #' @return See [stan_build_info()]. #' @@ -2304,7 +2304,7 @@ assert_stan_file_exists <- function(stan_file) { #' @param stan_file The model's Stan file, for the error when the binary #' will not run. #' @param tbb_dir The record's `tbb_dir`, or `NULL` without a usable record. -#' @return A named list with cmdstanr-style argument names and default +#' @return A named list with CmdStanR-style argument names and default #' values. parse_cmdstan_args <- function(model_binary, method, stan_file, tbb_dir) { withr::with_path( diff --git a/R/path.R b/R/path.R index 84bb1c2c0..732fb2225 100644 --- a/R/path.R +++ b/R/path.R @@ -99,7 +99,7 @@ cmdstan_path <- function() { path } -#' The selected installation, checked right before a program runs out of it +#' The selected installation, rechecked right before make or stanc runs from it #' #' `cmdstan_path()` returns the path cached when it was set, so an #' installation deleted since then would otherwise surface as a failure to @@ -119,9 +119,10 @@ checked_cmdstan_path <- function() { path } -#' The selected installation's version as its makefile says now, since the -#' version `cmdstan_version()` caches goes stale when a checkout is rebuilt -#' in place. A missing installation keeps the cached version. +#' The selected installation's version, read from its makefile now +#' +#' `cmdstan_version()` caches the version, which goes stale when a checkout is +#' rebuilt in place. A missing installation keeps the cached version. #' @noRd current_cmdstan_version <- function() { path <- cmdstan_path() diff --git a/R/run.R b/R/run.R index 19f838ac4..b3dbdb63d 100644 --- a/R/run.R +++ b/R/run.R @@ -465,18 +465,16 @@ check_target_exe <- function(exe) { #' Turn a failed launch of the model executable into a readable error #' -#' Called when processx could not start the executable, which happens when -#' the file has lost its execute bit, for example after being unzipped from -#' R, or was built for another platform, and when the executable started -#' but could not answer `help-all`, for example because a library it was -#' linked against is gone. Nothing checks for either ahead of time, so the -#' launch is where they first show up. processx's own error gives a -#' relative path like `./bernoulli` and an errno. This one names the -#' executable, keeps the system's reason (for example "Permission denied") -#' or the executable's own output, and says how to rebuild it, or that -#' there is no Stan file to rebuild it from. When the TBB the build linked -#' against is no longer there it says so, since that's one likely cause -#' and reinstalling it is the other way out. +#' Called when processx could not start the executable (it lost its execute bit, +#' for example after being unzipped from R, or was built for another platform) +#' and when it started but could not answer `help-all` (a library it was linked +#' against is gone). Nothing checks for either ahead of time, so the launch is +#' where they first show up. processx's own error gives a relative path like +#' `./bernoulli` and an errno. This one names the executable, keeps the system's +#' reason (for example "Permission denied") or the executable's own output, and +#' says how to rebuild it, or that there is no Stan file to rebuild it from. +#' When the TBB the build linked against is no longer there it says so, since +#' that's one likely cause and reinstalling it is the other way out. #' #' @param exe_file Path to the executable. #' @param stan_file The model's Stan file, empty for a model created from an diff --git a/R/stanc.R b/R/stanc.R index c9fada8bf..afc16a0f4 100644 --- a/R/stanc.R +++ b/R/stanc.R @@ -80,7 +80,7 @@ derived_stanc_option_message <- function(flag) { ), "allow-undefined" = paste0( "`allow-undefined` cannot be set through `stanc_options`. ", - "Builds turn it on when a `user_header` is supplied, and ", + "It is on whenever a `user_header` is supplied, and ", "`$check_syntax()`, `$format()` and `$variables()` always use it." ), "use-opencl" = paste0( @@ -123,13 +123,13 @@ stanc_option_supplied <- function(stanc_options, flag) { FALSE } -#' Turn a `stanc_options` list into `stanc` command line arguments +#' Turn a `stanc_options` list into stanc command line arguments #' #' @param stanc_options (list) Named or unnamed stanc options. Logical values #' mark boolean flags and any other value is passed as `--name=value`. #' @param quote_values (logical) Quote the arguments for the `STANCFLAGS` -#' string handed to Make, which expands it through a shell? Arguments for -#' direct `stanc` calls are passed to processx as separate elements and must +#' string handed to make, which expands it through a shell? Arguments for +#' direct stanc calls are passed to processx as separate elements and must #' be left unquoted (#1227). #' @return A character vector of arguments, one per element. #' @noRd @@ -190,8 +190,8 @@ drop_overridden_stancflags <- function(local_flags, call_args) { #' Build stanc include-path arguments #' -#' Make receives include paths through `STANCFLAGS`, expands the value and hands -#' it to the shell, so `make_shell_quote()` quotes each path for both (#1230) +#' Include paths go to make through `STANCFLAGS`, which make expands and hands +#' to the shell, so `make_shell_quote()` quotes each path for both (#1230) #' inside a single `--include-paths=` flag. Direct calls through processx #' instead need the flag and comma-separated paths as separate, unquoted #' arguments. @@ -199,10 +199,10 @@ drop_overridden_stancflags <- function(local_flags, call_args) { #' @param include_paths A character vector of directories containing files used #' in Stan `#include` directives, or `NULL`. #' @param direct_call A logical indicating whether the arguments will be passed -#' directly to stanc through processx instead of through Make. +#' directly to stanc through processx instead of through make. #' #' @return `NULL` if `include_paths` is `NULL`; otherwise, a single -#' `--include-paths=` argument for Make or two arguments for a direct call. +#' `--include-paths=` argument for make or two arguments for a direct call. #' @noRd include_paths_stanc3_args <- function(include_paths = NULL, direct_call = FALSE) { stancflags <- NULL @@ -224,18 +224,18 @@ include_paths_stanc3_args <- function(include_paths = NULL, direct_call = FALSE) stancflags } -#' Ask Make for `STANCFLAGS`, one argument per line +#' Ask make for `STANCFLAGS`, one argument per line #' -#' CmdStan's `print-%` rule echoes a variable through the shell, which strips the -#' quotes, so `make print-STANCFLAGS` returns `--filename-in-msg='/my dir'` as -#' two words (#1232). This rule hands `$(STANCFLAGS)` to the shell the way the -#' stanc recipe does and prints what the shell delivers, so the result holds +#' CmdStan's `print-%` rule echoes a variable through the shell, which strips +#' the quotes, so `make print-STANCFLAGS` returns `--filename-in-msg='/my dir'` +#' as two words (#1232). This rule hands `$(STANCFLAGS)` to the shell the way +#' the stanc recipe does and prints what the shell delivers, so the result holds #' exactly the arguments stanc gets from make. Each line carries a prefix that #' tells it apart from other make output. The rule lives in a temporary makefile #' rather than an `--eval` argument because users may have a make too old for -#' `--eval`; the one Apple ships with macOS is. The fragment's first line removes -#' the fragment from `MAKEFILE_LIST` so a value that reads the list sees the same -#' makefiles the real build does. +#' `--eval`; the one Apple ships with macOS is. The fragment's first line +#' removes the fragment from `MAKEFILE_LIST` so a value that reads the list sees +#' the same makefiles the real build does. #' #' @param cmdstan_path (string) The CmdStan directory. #' @param make_args (character) Command-line variable assignments (`NAME=value`) diff --git a/R/utils.R b/R/utils.R index 941f3e2f6..1c2a1648a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -755,11 +755,12 @@ parse_make_print_flag <- function(flag_name, stdout) { sub(pattern, "", trimws(lines[matches]), perl = TRUE) } -#' Quote words for a `STANCFLAGS` value handed to Make +#' Quote words for a `STANCFLAGS` value handed to make #' -#' Make expands the value and the shell splits it, so this doubles `$` for Make -#' and single-quotes any word holding a character the shell could interpret -#' (#1230). A word made only of characters neither touches stays as it is. +#' Since make expands the value and the shell then splits it, this doubles `$` +#' for make and single-quotes any word holding a character the shell could +#' interpret (#1230). A word made only of characters neither touches stays as +#' it is. #' #' @param x (character) Words, one per element. #' @return `x` with each element quoted as needed. diff --git a/man/cmdstan_model.Rd b/man/cmdstan_model.Rd index 4757889d6..2a164922a 100644 --- a/man/cmdstan_model.Rd +++ b/man/cmdstan_model.Rd @@ -73,7 +73,7 @@ to compile with the Stan model.} model (\code{stan_threads}, \code{stan_mpi}, \code{stan_opencl}, etc.), written as \code{list(NAME = value)}. Each entry is an assignment you could make in the \code{make/local} file, so \code{list(CXXFLAGS = "-O3")} rather than \code{"-O3"}. -Every entry must be named with a \code{Make} variable name, in any casing. +Every entry must be named with a make variable name, in any casing. Setting an option to \code{FALSE} or \code{NULL} passes an empty assignment such as \verb{STAN_THREADS=}. That empties the variable for this build, which turns a switch off, and overrides whatever \code{make/local} sets. See @@ -85,7 +85,7 @@ for using threading.} when compiling the model. A flag is given by name without the leading hyphens, as \code{list("O1")} or \code{list(O1 = TRUE)}, and an option that takes a value as \code{list(option = "value")}. See \code{\link[=stan_build_info]{stan_build_info()}} for an example -and the \href{https://mc-stan.org/docs/cmdstan-guide/stanc.html}{\code{stanc} chapter of the CmdStan User's Guide} for the +and the \href{https://mc-stan.org/docs/cmdstan-guide/stanc.html}{stanc chapter of the CmdStan User's Guide} for the available options. Options that CmdStanR sets from its own arguments cannot be passed here: \code{include-paths} (use \code{include_paths}), \code{warn-pedantic} (\code{pedantic}), \code{allow-undefined} (\code{user_header}), diff --git a/man/model-method-build_info.Rd b/man/model-method-build_info.Rd index 8613a135f..67d16c565 100644 --- a/man/model-method-build_info.Rd +++ b/man/model-method-build_info.Rd @@ -17,14 +17,14 @@ what the result holds. The method reports on the executable as it is now, so it also works on a model whose executable was replaced or whose build record is gone. -This method is different than the \verb{$cpp_options()} method, which answers a +This method is different from the \verb{$cpp_options()} method, which answers a narrower question: the C++ options this model object was created with. \verb{$build_info()} describes the executable itself, including what it reports -about its own build when run. The difference is clear when considering a -model created with \code{cmdstan_model(exe_file = )} from just an executable -with no build record: \verb{$cpp_options()} is empty, since no options were -given, but \verb{$build_info()} still reports whether the executable was built -with threading, OpenCL and so on. +about its own build when run. Take a model created with +\code{cmdstan_model(exe_file = )} from an executable with no build record: +\verb{$cpp_options()} is empty, since no options were given, but \verb{$build_info()} +still reports whether the executable was built with threading, OpenCL and +so on. } \examples{ \dontrun{ diff --git a/man/model-method-model-info.Rd b/man/model-method-model-info.Rd index e988c8579..7aa40dae8 100644 --- a/man/model-method-model-info.Rd +++ b/man/model-method-model-info.Rd @@ -26,7 +26,7 @@ executable path is set. \item \verb{$cmdstan_version()} returns the version of CmdStan that built the executable, as a string. \item \verb{$cpp_options()} returns a named list of C++ options, with names in their -\code{make} spelling. +make spelling. \item \verb{$user_header()} returns the absolute path to the user header as a string, or \code{NULL} if the model has no user header. \item \verb{$hpp_file()} returns the path to the \code{.hpp} file holding the C++ code diff --git a/man/stan_build_info.Rd b/man/stan_build_info.Rd index 050f6ea02..8cf726676 100644 --- a/man/stan_build_info.Rd +++ b/man/stan_build_info.Rd @@ -40,7 +40,7 @@ When the build record is available, there are four more fields: \itemize{ \item \code{configuration}: A list of the options the model was created with. \itemize{ -\item \code{cpp_options}: the list of options in their Make spelling, as +\item \code{cpp_options}: the list of options in their make spelling, as \verb{$cpp_options()} reports them. For example, \code{list(stan_threads = TRUE)} comes back as \code{list(STAN_THREADS = "true")}. \item \code{stanc_options}: the flags as given to stanc, in order. @@ -53,27 +53,27 @@ repeated here since \code{stanc_options} takes precedence. included files. When none were provided but the Stan program has includes this is set to the program's own directory. } -\item \code{dependencies}: A list describing the files the build read. Contains sublists -\code{stan_file}, \code{included_files}, \code{user_header} and \code{make_local}. \code{user_header} -and \code{make_local} are \code{NULL} when the build had none. \code{included_files} holds -one entry per file. Each entry has two fields: \code{built_from}, the path the -file had when the build ran, and \code{exists}, whether that path exists now. A -path that no longer exists is not necessarily a problem. For example, an \R -package may build its models at install time in a temporary directory that -is gone by the time the model is used. +\item \code{dependencies}: A list describing the files the build read. Contains +sublists \code{stan_file}, \code{included_files}, \code{user_header} and \code{make_local}. +\code{user_header} and \code{make_local} are \code{NULL} when the build had none. +\code{included_files} holds one entry per file. Each entry has two fields: +\code{built_from}, the path the file had when the build ran, and \code{exists}, whether +that path exists now. A path that no longer exists is not necessarily a +problem. For example, an \R package may build its models at install time in a +temporary directory that is gone by the time the model is used. \item \code{cmdstan}: A list containing the \code{path} and \code{version} of the CmdStan installation that built the executable, and whether that path still \code{exists}. This version and \code{reported_features$stan_version} will typically agree except when using a release candidate (\code{cmdstan$version} will have a release-candidate suffix whereas \code{reported_features$stan_version} comes from the Stan library headers the executable was compiled against and will not). -\item \code{untracked_dependencies}: A list of files the build depended on that CmdStanR -cannot follow, so a change to them does not automatically trigger a rebuild. -An empty list means nothing of the kind was found. Each file is reported as -a sublist with two fields: \code{kind}, which is \code{"make_local_include"} when -\code{make/local} includes another makefile or \code{"user_header_include"} when the -user header includes other headers, and \code{detected_in}, the file the include -was found in. +\item \code{untracked_dependencies}: A list of files the build depended on that +CmdStanR cannot follow, so a change to them does not automatically trigger a +rebuild. An empty list means nothing of the kind was found. Each file is +reported as a sublist with two fields: \code{kind}, which is +\code{"make_local_include"} when \code{make/local} includes another makefile or +\code{"user_header_include"} when the user header includes other headers, and +\code{detected_in}, the file the include was found in. } The result leaves out some of what the record holds: the file hashes the diff --git a/tests/testthat/test-cpp-options.R b/tests/testthat/test-cpp-options.R index 563641f68..80f052c74 100644 --- a/tests/testthat/test-cpp-options.R +++ b/tests/testthat/test-cpp-options.R @@ -135,7 +135,7 @@ test_that("assert_valid_cpp_options sends makefile syntax to make/local", { expect_error( assert_valid_cpp_options(list(entry)), paste0( - "Make flags cannot be passed through `cpp_options`. Set them in ", + "`cpp_options` cannot pass flags to make. Set them in ", "`make/local` with `cmdstan_make_local()`, for example ", "`MAKEFLAGS += -j4`." ), @@ -162,7 +162,7 @@ test_that("assert_valid_cpp_options rejects -B and --always-make", { expect_error( assert_valid_cpp_options(list(entry)), paste0( - "Make flags cannot be passed through `cpp_options`. `", entry, + "`cpp_options` cannot pass flags to make. `", entry, "` rebuilds everything; pass `force_recompile = TRUE` instead." ), fixed = TRUE @@ -175,7 +175,7 @@ test_that("assert_valid_cpp_options sends -f entries to make/local's include", { expect_error( assert_valid_cpp_options(list(entry)), paste0( - "Make flags cannot be passed through `cpp_options`. To read another ", + "`cpp_options` cannot pass flags to make. To read another ", "makefile add `include other.mk` to `make/local`, for example ", "`cmdstan_make_local(cpp_options = list(\"include other.mk\"))`." ), @@ -185,7 +185,7 @@ test_that("assert_valid_cpp_options sends -f entries to make/local's include", { expect_error( assert_valid_cpp_options(list("-f")), paste0( - "Make flags cannot be passed through `cpp_options`. Set them in ", + "`cpp_options` cannot pass flags to make. Set them in ", "`make/local` with `cmdstan_make_local()`, for example ", "`MAKEFLAGS += -j4`." ), @@ -193,12 +193,12 @@ test_that("assert_valid_cpp_options sends -f entries to make/local's include", { ) }) -test_that("assert_valid_cpp_options requires Make variable names", { +test_that("assert_valid_cpp_options requires make variable names", { for (options in list(list("CXXFLAGS+" = "-x"), list("2FOO" = 1))) { expect_error( assert_valid_cpp_options(options), paste0( - "`cpp_options` names must be Make variable names, made of letters, ", + "`cpp_options` names must be make variable names, made of letters, ", "digits and underscores and not starting with a digit. `", names(options), "` is not one." ), @@ -264,7 +264,7 @@ test_that("a thread request needs threading reported on", { ) expect_error( assert_valid_threads(2L, off, multiple_chains = TRUE), - "'threads_per_chain'", fixed = TRUE + "`threads_per_chain`", fixed = TRUE ) for (features in list(on, off, unknown)) { diff --git a/tests/testthat/test-model-compile.R b/tests/testthat/test-model-compile.R index c66f870a9..2a3b9192e 100644 --- a/tests/testthat/test-model-compile.R +++ b/tests/testthat/test-model-compile.R @@ -302,7 +302,7 @@ test_that("compiling stops on stanc options cmdstanr sets itself", { fragments <- list( "include-paths" = "Pass the directories with the `include_paths` argument.", "warn-pedantic" = "Use `pedantic = TRUE`.", - "allow-undefined" = "Builds turn it on when a `user_header` is supplied", + "allow-undefined" = "It is on whenever a `user_header` is supplied", "use-opencl" = "Use `cpp_options = list(stan_opencl = TRUE)`, which turns it on.", "name" = "The model name comes from the name of the Stan file." ) @@ -433,7 +433,7 @@ test_that("check_syntax() works", { ) expect_error( mod_ok$check_syntax(stanc_options = list("allow-undefined")), - "Builds turn it on when a `user_header` is supplied", + "It is on whenever a `user_header` is supplied", fixed = TRUE ) diff --git a/tests/testthat/test-opencl.R b/tests/testthat/test-opencl.R index 582e11fcd..7516882e6 100644 --- a/tests/testthat/test-opencl.R +++ b/tests/testthat/test-opencl.R @@ -6,24 +6,24 @@ test_that("all methods error when opencl_ids is used with non OpenCL model", { mod <- cmdstan_model(stan_file = stan_file, force_recompile = TRUE) expect_error( mod$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0), chains = 1), - "'opencl_ids' is set but the executable does not report OpenCL as enabled.", + "`opencl_ids` is set but the executable does not report OpenCL as enabled.", fixed = TRUE ) expect_error( mod$optimize(data = testing_data("bernoulli"), opencl_ids = c(0, 0)), - "'opencl_ids' is set but the executable does not report OpenCL as enabled.", + "`opencl_ids` is set but the executable does not report OpenCL as enabled.", fixed = TRUE ) expect_error( mod$variational(data = testing_data("bernoulli"), opencl_ids = c(0, 0)), - "'opencl_ids' is set but the executable does not report OpenCL as enabled.", + "`opencl_ids` is set but the executable does not report OpenCL as enabled.", fixed = TRUE ) stan_file_gq <- testing_stan_file("bernoulli_ppc") mod_gq <- cmdstan_model(stan_file = stan_file_gq, force_recompile = TRUE) expect_error( mod_gq$generate_quantities(fitted_params = fit, data = testing_data("bernoulli"), opencl_ids = c(0, 0)), - "'opencl_ids' is set but the executable does not report OpenCL as enabled.", + "`opencl_ids` is set but the executable does not report OpenCL as enabled.", fixed = TRUE ) }) diff --git a/vignettes/cmdstanr-internals.Rmd b/vignettes/cmdstanr-internals.Rmd index ef4b7b11e..96fb05d48 100644 --- a/vignettes/cmdstanr-internals.Rmd +++ b/vignettes/cmdstanr-internals.Rmd @@ -153,7 +153,7 @@ model { ") ``` -To turn on pedantic mode when compiling set `pedantic=TRUE` in the call to +To turn on pedantic mode, set `pedantic = TRUE` in the call to `cmdstan_model()`. ```{r pedantic-compile, collapse = TRUE} @@ -246,11 +246,11 @@ mod <- cmdstan_model(stan_file, dir = "path/to/directory/for/executable") ### The build record -Starting with v1.0, to help it determine whether a rebuild is necessary CmdStanR -writes a hidden JSON file next to the executable that records how the executable -was built: the Stan file and the files it includes, the options passed to -`stanc` and `make`, the CmdStan installation, and a hash of the executable -itself. The file is named after the executable, so `bernoulli` is described by +Starting with v1.0, CmdStanR writes a hidden JSON file next to the executable so +it can tell whether a rebuild is needed. The file records how the executable was +built: the Stan file and the files it includes, the options passed to stanc and +make, the CmdStan installation, and a hash of the executable itself. The file is +named after the executable, so `bernoulli` is described by `.bernoulli.cmdstanr.json`. ```{r build-record} @@ -267,8 +267,8 @@ reports only what the executable says about itself. ```{r build-info} mod$build_info() -# demonstrating stan_build_info even though here we have the model object -# so we can use mod$build_info() +# demonstrating stan_build_info even though we can use mod$build_info() +# since we have the model object available stan_build_info(mod$exe_file()) ``` @@ -280,7 +280,7 @@ doesn't hide the file from git). You can ignore all record files using If the directory is inside an R package, we recommend adding a matching regular expression to `.Rbuildignore`, such as `\..*\.cmdstanr\.json$`. -In general, if you move the executable somewhere move the build record with it. +If you move the executable, move the build record with it. If a build step copies the executable somewhere else, such as a CI artifact, a container image or a shared build directory, copy the record with it. @@ -293,7 +293,7 @@ changing them does not automatically trigger a rebuild and you should manually force recompilation: - the C++ toolchain -- environment variables the compiler or `make` reads +- environment variables the compiler or make reads - CmdStan or the Stan Math library modified in place - a makefile that `make/local` includes - headers that a `user_header` includes From 378ee34a841e8332bba50075ac4669b5291caccf Mon Sep 17 00:00:00 2001 From: jgabry Date: Thu, 24 Sep 2026 16:39:00 -0600 Subject: [PATCH 2/2] Quote code in messages with backticks The messages written for v1.0 put argument names, methods and typed expressions in backticks, while the older messages used single quotes for the same things, so a user could meet `init` in one error and 'init' in the next. This makes backticks the rule for code the reader types: arguments, methods such as `$code()`, classes, options, expressions like `quiet = FALSE`, shell commands, and literal values as `"newton"`. Values quoted back at the user, such as paths, user header files and Stan data variable names, keep their single quotes, since they are not code. Program and package names are bare words. The tests and snapshots that match the changed text are updated. Two prose lines that still backticked stanc as a program name are fixed as well. The timeout test in test-install.R expected a message install_cmdstan() prints only when a release URL is given, and with a doubled asterisk; the branch only runs when no installation exists in the temporary directory yet, so CI never saw it. It now expects the message the default path prints. Part of #1258. --- R/args.R | 32 +++++++++++++------------- R/build.R | 2 +- R/data.R | 10 ++++---- R/fit.R | 14 +++++------ R/install.R | 28 ++++++++++++---------- R/model.R | 26 ++++++++++----------- R/path.R | 4 ++-- R/run.R | 4 ++-- R/stanc.R | 2 +- R/utils.R | 2 +- R/zzz.R | 4 ++-- tests/testthat/_snaps/fit-gq.md | 10 ++++---- tests/testthat/_snaps/fit-laplace.md | 2 +- tests/testthat/_snaps/fit-mcmc.md | 10 ++++---- tests/testthat/_snaps/fit-mle.md | 2 +- tests/testthat/_snaps/fit-vb.md | 6 ++--- tests/testthat/_snaps/install.md | 2 +- tests/testthat/_snaps/threads.md | 2 +- tests/testthat/test-build-info.R | 4 ++-- tests/testthat/test-data.R | 2 +- tests/testthat/test-fit-shared.R | 6 ++--- tests/testthat/test-install.R | 16 ++++++------- tests/testthat/test-json.R | 8 +++---- tests/testthat/test-model-code-print.R | 6 ++--- tests/testthat/test-model-compile.R | 18 +++++++-------- tests/testthat/test-model-init.R | 24 +++++++++---------- tests/testthat/test-model-laplace.R | 6 ++--- tests/testthat/test-model-methods.R | 2 +- tests/testthat/test-model-optimize.R | 8 +++---- tests/testthat/test-model-variables.R | 2 +- tests/testthat/test-path.R | 2 +- tests/testthat/test-threads.R | 2 +- vignettes/cmdstanr-internals.Rmd | 2 +- 33 files changed, 137 insertions(+), 133 deletions(-) diff --git a/R/args.R b/R/args.R index 7e09491d3..c322629f6 100644 --- a/R/args.R +++ b/R/args.R @@ -841,10 +841,10 @@ validate_optimize_args <- function(self) { # check that arg is positive or NULL and that algorithm='lbfgs' or 'bfgs' is # explicitly specified (error if not or if 'newton') if (!is.null(self[[arg]]) && is.null(self$algorithm)) { - stop("Please specify 'algorithm' in order to use '", arg, "'.", call. = FALSE) + stop("Please specify `algorithm` in order to use `", arg, "`.", call. = FALSE) } if (!is.null(self[[arg]]) && isTRUE(self$algorithm == "newton")) { - stop("'", arg, "' can't be used when algorithm is 'newton'.", call. = FALSE) + stop("`", arg, "` can't be used when algorithm is `\"newton\"`.", call. = FALSE) } checkmate::assert_number(self[[arg]], .var.name = arg, lower = 0, null.ok = TRUE) } @@ -852,7 +852,7 @@ validate_optimize_args <- function(self) { # history_size only available for lbfgs if (!is.null(self$history_size)) { if (!isTRUE(self$algorithm == "lbfgs")) { - stop("'history_size' is only allowed if 'algorithm' is specified as 'lbfgs'.", call. = FALSE) + stop("`history_size` is only allowed if `algorithm` is specified as `\"lbfgs\"`.", call. = FALSE) } else { checkmate::assert_integerish(self$history_size, lower = 1, len = 1, null.ok = FALSE) self$history_size <- as.integer(self$history_size) @@ -875,7 +875,7 @@ validate_laplace_args <- function(self) { checkmate::assert_flag(self$jacobian, null.ok = FALSE) if (self$mode_object$metadata()$jacobian != self$jacobian) { stop( - "'jacobian' argument to optimize and laplace must match!\n", + "`jacobian` argument to optimize and laplace must match!\n", "laplace was called with jacobian=", self$jacobian, "\n", "optimize was run with jacobian=", as.logical(self$mode_object$metadata()$jacobian), call. = FALSE @@ -1171,13 +1171,13 @@ process_init.list <- function(init, num_procs, model_variables = NULL, warn_partial = getOption("cmdstanr_warn_inits", TRUE), ...) { if (!all(sapply(init, function(x) is.list(x) && !is.data.frame(x)))) { - stop("If 'init' is a list it must be a list of lists.", call. = FALSE) + stop("If `init` is a list it must be a list of lists.", call. = FALSE) } if (length(init) != num_procs) { - stop("'init' has the wrong length. See documentation of 'init' argument.", call. = FALSE) + stop("`init` has the wrong length. See documentation of `init` argument.", call. = FALSE) } if (any(sapply(init, function(x) length(x) == 0))) { - stop("'init' contains empty lists.", call. = FALSE) + stop("`init` contains empty lists.", call. = FALSE) } if (!is.null(model_variables)) { missing_parameter_values <- list() @@ -1215,9 +1215,9 @@ process_init.list <- function(init, num_procs, model_variables = NULL, } if (any(grepl("\\[", names(unlist(init))))) { stop( - "'init' contains entries with parameter names that include square-brackets, which is not permitted. ", + "`init` contains entries with parameter names that include square-brackets, which is not permitted. ", "To supply inits for a vector, matrix or array of parameters, ", - "create a single entry with the parameter's name in the 'init' list ", + "create a single entry with the parameter's name in the `init` list ", "and specify initial values for the entire parameter container.", call. = FALSE) } @@ -1249,8 +1249,8 @@ process_init.function <- function(init, num_procs, model_variables = NULL, has_chain_id <- !is.null(args) if (has_chain_id) { if (!identical(names(args), "chain_id")) { - stop("If 'init' is a function it must have zero arguments ", - "or only argument 'chain_id'.", call. = FALSE) + stop("If `init` is a function it must have zero arguments ", + "or only argument `chain_id`.", call. = FALSE) } } @@ -1258,7 +1258,7 @@ process_init.function <- function(init, num_procs, model_variables = NULL, for (i in seq_len(num_procs)) { init_list[[i]] <- if (has_chain_id) init(i) else init() if (!is.list(init_list[[i]]) || is.data.frame(init_list[[i]])) { - stop("If 'init' is a function it must return a single list.", call. = FALSE) + stop("If `init` is a function it must return a single list.", call. = FALSE) } } process_init(init_list, num_procs, model_variables, warn_partial) @@ -1521,14 +1521,14 @@ validate_init <- function(init, num_procs) { return(invisible(TRUE)) } if (!is.numeric(init) && !is.character(init)) { - stop("Invalid 'init' specification. See documentation of 'init' argument.", + stop("Invalid `init` specification. See documentation of `init` argument.", call. = FALSE) } else if (is.numeric(init) && (length(init) > 1 || init < 0)) { - stop("If 'init' is numeric it must be a single real number >= 0.", + stop("If `init` is numeric it must be a single real number >= 0.", call. = FALSE) } else if (is.character(init)) { if (length(init) != 1 && length(init) != num_procs) { - stop("If 'init' is specified as a character vector, its length must be ", + stop("If `init` is specified as a character vector, its length must be ", "1 or equal to the number of chains or Pathfinder paths.", call. = FALSE) } @@ -1567,7 +1567,7 @@ validate_seed <- function(seed, num_procs) { } checkmate::assert_integerish(seed, lower = 0) if (length(seed) > 1 && length(seed) != num_procs) { - stop("If 'seed' is specified it must be a single integer or one per chain.", + stop("If `seed` is specified it must be a single integer or one per chain.", call. = FALSE) } invisible(TRUE) diff --git a/R/build.R b/R/build.R index 0480a668c..0eb0d3a29 100644 --- a/R/build.R +++ b/R/build.R @@ -358,7 +358,7 @@ inspect_executable <- function(exe_file) { features <- reported_features_from_exe(exe_file) if (is.null(features[["stan_version"]])) { stop( - "Running '", exe_file, "' with the argument 'info' did not report a ", + "Running '", exe_file, "' with the argument `info` did not report a ", "Stan version, so it is either not a CmdStan executable or cannot be ", "run.", call. = FALSE diff --git a/R/data.R b/R/data.R index 35669f4c3..3eb181af5 100644 --- a/R/data.R +++ b/R/data.R @@ -92,7 +92,7 @@ #' write_stan_json <- function(data, file, always_decimal = FALSE) { if (!is.list(data)) { - stop("'data' must be a list.", call. = FALSE) + stop("`data` must be a list.", call. = FALSE) } if (!is.character(file) || !nzchar(file)) { stop("The supplied filename is invalid!", call. = FALSE) @@ -102,11 +102,11 @@ write_stan_json <- function(data, file, always_decimal = FALSE) { if (length(data) > 0 && (length(data_names) == 0 || length(data_names) != sum(nzchar(data_names)))) { - stop("All elements in 'data' list must have names.", call. = FALSE) + stop("All elements in `data` list must have names.", call. = FALSE) } if (anyDuplicated(data_names) != 0) { - stop("Duplicate names not allowed in 'data'.", call. = FALSE) + stop("Duplicate names not allowed in `data`.", call. = FALSE) } for (var_name in data_names) { @@ -280,7 +280,7 @@ process_data <- function(data, model_variables = NULL) { path <- tempfile(pattern = "standata-", fileext = ".json") write_stan_json(data = data, file = path, always_decimal = !is.null(model_variables)) } else { - stop("'data' should be a path or a named list.", call. = FALSE) + stop("`data` should be a path or a named list.", call. = FALSE) } path } @@ -452,7 +452,7 @@ process_fitted_params <- function(fitted_params) { paths <- draws_to_csv(posterior::as_draws_array(fitted_params)) } else { stop( - "'fitted_params' must be a list of paths to CSV files, ", + "`fitted_params` must be a list of paths to CSV files, ", "a CmdStanMCMC, CmdStanMLE, CmdStanLaplace, CmdStanVB, or ", "CmdStanPathfinder object, ", "a posterior::draws_array or a posterior::draws_matrix.", call. = FALSE) diff --git a/R/fit.R b/R/fit.R index 2233c39cc..00a44dac7 100644 --- a/R/fit.R +++ b/R/fit.R @@ -77,7 +77,7 @@ CmdStanFit <- R6::R6Class( base::print(out, row.names = FALSE) if (max_rows < total_rows) { cat("\n # showing", max_rows, "of", total_rows, - "rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option)\n") + "rows (change via `max_rows` argument or `cmdstanr_max_rows` option)\n") } invisible(self) }, @@ -180,7 +180,7 @@ save_object <- function(file, format = c("rds", "qs2"), ...) { saveRDS(self, file = file, ...) } else { if (!requireNamespace("qs2", quietly = TRUE)) { - stop("The 'qs2' package is required for format = \"qs2\".", call. = FALSE) + stop("The qs2 package is required for `format = \"qs2\"`.", call. = FALSE) } qs2::qs_save(self, file = file, ...) } @@ -306,7 +306,7 @@ draws <- function(variables = NULL, inc_warmup = FALSE, format = getOption("cmds stop("Fitting failed. Unable to retrieve the draws.", call. = FALSE) } if (inc_warmup) { - warning("'inc_warmup' is ignored except when used with CmdStanMCMC objects.", + warning("`inc_warmup` is ignored except when used with CmdStanMCMC objects.", call. = FALSE) } if (is.null(private$draws_)) { @@ -628,7 +628,7 @@ unconstrain_draws <- function(files = NULL, draws = NULL, } } else if (!is.null(draws)) { if (inc_warmup) { - message("'inc_warmup' cannot be used with a draws object. Ignoring.") + message("`inc_warmup` cannot be used with a draws object. Ignoring.") } } } else { @@ -1371,7 +1371,7 @@ CmdStanFit$set("public", name = "profiles", value = profiles) code <- function() { stan_code <- self$runset$stan_code() if (is.null(stan_code)) { - warning("'$code()' will return NULL because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) + warning("`$code()` will return NULL because the `CmdStanModel` was not created with a Stan file.", call. = FALSE) } stan_code } @@ -1675,7 +1675,7 @@ CmdStanMCMC <- R6::R6Class( loo <- function(variables = "log_lik", r_eff = FALSE, moment_match = FALSE, ...) { require_suggested_package("loo") if (length(variables) != 1) { - stop("Only a single variable name is allowed for the 'variables' argument.", call. = FALSE) + stop("Only a single variable name is allowed for the `variables` argument.", call. = FALSE) } LLarray <- self$draws(variables, format = "draws_array") if (is.logical(r_eff)) { @@ -2500,7 +2500,7 @@ CmdStanGQ <- R6::R6Class( stop("Generating quantities for all MCMC chains failed. Unable to retrieve the generated quantities.", call. = FALSE) } if (inc_warmup) { - warning("'inc_warmup' is ignored except when used with CmdStanMCMC objects.", + warning("`inc_warmup` is ignored except when used with CmdStanMCMC objects.", call. = FALSE) } format <- assert_valid_draws_format(format) diff --git a/R/install.R b/R/install.R index c1103cbfa..62d1e46d6 100644 --- a/R/install.R +++ b/R/install.R @@ -413,7 +413,7 @@ cmdstan_make_local <- function(dir = cmdstan_path(), check_cmdstan_toolchain <- function(fix = FALSE, quiet = FALSE) { if (isTRUE(fix)) { warning( - "The 'fix' argument is deprecated as of CmdStanR 1.0.0 and will be removed in a future release.", + "The `fix` argument is deprecated as of CmdStanR 1.0.0 and will be removed in a future release.", call. = FALSE ) } @@ -770,14 +770,16 @@ build_example <- function(dir, cores, quiet, timeout) { build_status_ok <- function(process_log, quiet = FALSE) { if (process_log$timeout) { if (quiet) { - end_warning <- - " and running again with 'quiet=FALSE' to see full installation output." + end_warning <- paste0( + " and running again with `quiet = FALSE` to see full ", + "installation output." + ) } else { end_warning <- "." } warning( "The build process timed out. ", - "Try increasing the value of the 'timeout' argument", + "Try increasing the value of the `timeout` argument", end_warning, call. = FALSE ) @@ -786,8 +788,10 @@ build_status_ok <- function(process_log, quiet = FALSE) { if (is.na(process_log$status) || process_log$status != 0) { if (quiet) { - end_warning <- - " and/or try again with 'quiet=FALSE' to see full installation output." + end_warning <- paste0( + " and/or try again with `quiet = FALSE` to see full ", + "installation output." + ) } else { end_warning <- "." } @@ -856,16 +860,16 @@ check_unix_make <- function() { if (!nzchar(make_path)) { if (os_is_macos()) { stop( - "The 'make' tool was not found. ", - "Please install the command line tools for Mac with 'xcode-select --install' ", + "The make tool was not found. ", + "Please install the command line tools for Mac with `xcode-select --install` ", "or install Xcode from the app store. ", "Then restart R and run cmdstanr::check_cmdstan_toolchain().", call. = FALSE ) } else { stop( - "The 'make' tool was not found. ", - "Please install 'make', restart R, and then run cmdstanr::check_cmdstan_toolchain().", + "The make tool was not found. ", + "Please install make, restart R, and then run cmdstanr::check_cmdstan_toolchain().", call. = FALSE ) } @@ -880,7 +884,7 @@ check_unix_cpp_compiler <- function() { if (os_is_macos()) { stop( "A suitable C++ compiler was not found. ", - "Please install the command line tools for Mac with 'xcode-select --install' ", + "Please install the command line tools for Mac with `xcode-select --install` ", "or install Xcode from the app store. ", "Then restart R and run cmdstanr::check_cmdstan_toolchain().", call. = FALSE @@ -888,7 +892,7 @@ check_unix_cpp_compiler <- function() { } else { stop( "A C++ compiler was not found. ", - "Please install the 'clang++' or 'g++' compiler, restart R, ", + "Please install the clang++ or g++ compiler, restart R, ", "and run cmdstanr::check_cmdstan_toolchain().", call. = FALSE ) diff --git a/R/model.R b/R/model.R index acef372cd..4d05830fc 100644 --- a/R/model.R +++ b/R/model.R @@ -222,7 +222,7 @@ cmdstan_model <- function(stan_file = NULL, if (is.null(exe_file) && is.null(stan_file)) { stop( "Unable to create a `CmdStanModel` object. ", - "Both 'stan_file' and 'exe_file' are undefined.", + "Both `stan_file` and `exe_file` are undefined.", call. = FALSE ) } @@ -482,14 +482,14 @@ CmdStanModel <- R6::R6Class( }, code = function() { if (length(private$stan_code_) == 0) { - warning("'$code()' will return NULL because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) + warning("`$code()` will return NULL because the `CmdStanModel` was not created with a Stan file.", call. = FALSE) return(NULL) } private$stan_code_ }, print = function(line_numbers = getOption("cmdstanr_print_line_numbers", FALSE)) { if (length(private$stan_code_) == 0) { - stop("'$print()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) + stop("`$print()` cannot be used because the `CmdStanModel` was not created with a Stan file.", call. = FALSE) } lines <- self$code() if (line_numbers) { @@ -528,7 +528,7 @@ CmdStanModel <- R6::R6Class( }, hpp_file = function() { if (!self$has_stan_file()) { - stop("'$hpp_file()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) + stop("`$hpp_file()` cannot be used because the `CmdStanModel` was not created with a Stan file.", call. = FALSE) } private$hpp_file_ }, @@ -669,7 +669,7 @@ NULL variables <- function() { if (length(self$stan_file()) == 0) { stop( - "'$variables()' cannot be used because the 'CmdStanModel' ", + "`$variables()` cannot be used because the `CmdStanModel` ", "was not created with a Stan file.", call. = FALSE ) @@ -757,7 +757,7 @@ check_syntax <- function(pedantic = FALSE, stanc_options = list(), quiet = FALSE) { if (length(self$stan_file()) == 0) { - stop("'$check_syntax()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) + stop("`$check_syntax()` cannot be used because the `CmdStanModel` was not created with a Stan file.", call. = FALSE) } assert_stan_file_exists(self$stan_file()) check_syntax_stan_file( @@ -824,7 +824,7 @@ check_syntax_stan_file <- function(stan_file, #' should 'canonicalize' the Stan model, removing things like deprecated syntax. #' Default is `FALSE`. If `TRUE`, all canonicalizations are run. You can also #' supply a list of strings which represent options. In that case the options -#' are passed to `stanc`. See the +#' are passed to stanc. See the #' [User's guide section](https://mc-stan.org/docs/stan-users-guide/stanc-pretty-printing.html#canonicalizing) #' for available canonicalization options. #' @param backup (logical) If `TRUE`, create a backup before writing to the @@ -879,7 +879,7 @@ format <- function(overwrite_file = FALSE, quiet = FALSE) { if (length(self$stan_file()) == 0) { stop( - "'$format()' cannot be used because the 'CmdStanModel'", + "`$format()` cannot be used because the `CmdStanModel`", " was not created with a Stan file.", call. = FALSE ) } @@ -1476,7 +1476,7 @@ laplace <- function(data = NULL, save_cmdstan_config = getOption("cmdstanr_save_config", FALSE)) { private$assert_current() if (!is.null(mode) && !is.null(opt_args)) { - stop("Cannot specify both 'opt_args' and 'mode' arguments.", call. = FALSE) + stop("Cannot specify both `opt_args` and `mode` arguments.", call. = FALSE) } procs <- CmdStanProcs$new( num_procs = 1, @@ -1491,7 +1491,7 @@ laplace <- function(data = NULL, cmdstan_mode <- mode } else { if (!(is.character(mode) && length(mode) == 1)) { - stop("If not NULL or a CmdStanMLE object then 'mode' must be a path to a CSV file.", call. = FALSE) + stop("If not NULL or a CmdStanMLE object then `mode` must be a path to a CSV file.", call. = FALSE) } cmdstan_mode <- as_cmdstan_fit(mode) } @@ -1517,7 +1517,7 @@ laplace <- function(data = NULL, if (cmdstan_mode$return_codes() != 0) { stop( "Optimization failed.\n", - "Consider supplying the 'mode' argument or additional optimizer args.", + "Consider supplying the `mode` argument or additional optimizer args.", call. = FALSE ) } @@ -1811,10 +1811,10 @@ pathfinder <- function(data = NULL, private$assert_current() if (!is.null(num_threads)) { if (!is.null(threads)) { - stop("Cannot specify both 'threads' and deprecated 'num_threads'.", call. = FALSE) + stop("Cannot specify both `threads` and deprecated `num_threads`.", call. = FALSE) } warning( - "'num_threads' is deprecated as of CmdStanR 1.0.0 and will be removed in a future release. Please use 'threads' instead.", + "`num_threads` is deprecated as of CmdStanR 1.0.0 and will be removed in a future release. Please use `threads` instead.", call. = FALSE ) threads <- num_threads diff --git a/R/path.R b/R/path.R index 732fb2225..3cfc6e3a0 100644 --- a/R/path.R +++ b/R/path.R @@ -224,7 +224,7 @@ resolve_cmdstan_path_from_env <- function() { if (!dir.exists(path)) { warning( "CmdStan path not set. Can't find directory specified by environment ", - "variable 'CMDSTAN'.", + "variable `CMDSTAN`.", call. = FALSE ) return(NA_character_) @@ -238,7 +238,7 @@ resolve_cmdstan_path_from_env <- function() { if (is.null(path)) { warning( "CmdStan path not set. No CmdStan installation found in the path ", - "specified by the environment variable 'CMDSTAN'.", + "specified by the environment variable `CMDSTAN`.", call. = FALSE ) return(NA_character_) diff --git a/R/run.R b/R/run.R index b3dbdb63d..a6b42c2ed 100644 --- a/R/run.R +++ b/R/run.R @@ -96,7 +96,7 @@ CmdStanRun <- R6::R6Class( if (!length(private$latent_dynamics_files_)) { stop( "No latent dynamics files found. ", - "Set 'save_latent_dynamics=TRUE' when fitting the model.", + "Set `save_latent_dynamics = TRUE` when fitting the model.", call. = FALSE ) } @@ -259,7 +259,7 @@ CmdStanRun <- R6::R6Class( current_files <- self$metric_files(include_failed = TRUE) # used so we get error if 0 files if (!length(current_files)) { stop( - "No metric files found. Make sure to set 'save_metric=TRUE' when fitting the model.", + "No metric files found. Make sure to set `save_metric = TRUE` when fitting the model.", call. = FALSE ) } diff --git a/R/stanc.R b/R/stanc.R index afc16a0f4..0046639cf 100644 --- a/R/stanc.R +++ b/R/stanc.R @@ -33,7 +33,7 @@ assert_valid_stanc_options <- function(stanc_options) { if (startsWith(name, "--")) { stop("No leading hyphens allowed in stanc options (", name, "). ", "Use options without leading hyphens, for example ", - "`stanc_options = list('warn-uninitialized')`", + "`stanc_options = list(\"warn-uninitialized\")`", call. = FALSE) } # The flag is the part before the first `=`, wherever the name occurs. diff --git a/R/utils.R b/R/utils.R index 1c2a1648a..0add1353f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -110,7 +110,7 @@ warn_if_ignored_msys_toolchain_env <- function() { return(invisible(NULL)) } warning( - "Environment variable 'CMDSTANR_USE_MSYS_TOOLCHAIN' is deprecated and ignored. ", + "Environment variable `CMDSTANR_USE_MSYS_TOOLCHAIN` is deprecated and ignored. ", "CmdStanR now requires CmdStan v", cmdstan_min_version(), " or newer.\n", "If you need legacy MSYS toolchain support, use an older CmdStanR release.", call. = FALSE diff --git a/R/zzz.R b/R/zzz.R index decc6cec6..0cc5c1f63 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -22,9 +22,9 @@ startup_messages <- function() { if (!is.null(deprecated_no_ver_check_option) || !is.na(deprecated_no_ver_check_env)) { warning( - "The 'CMDSTANR_NO_VER_CHECK' option and environment variable are ", + "The `CMDSTANR_NO_VER_CHECK` option and environment variable are ", "deprecated as of CmdStanR 1.0.0 and will be removed in a future ", - "release. Use lowercase 'cmdstanr_no_ver_check' instead.", + "release. Use lowercase `cmdstanr_no_ver_check` instead.", call. = FALSE ) } diff --git a/tests/testthat/_snaps/fit-gq.md b/tests/testthat/_snaps/fit-gq.md index 77e09252f..7230fb3a7 100644 --- a/tests/testthat/_snaps/fit-gq.md +++ b/tests/testthat/_snaps/fit-gq.md @@ -15,7 +15,7 @@ y_rep[9] y_rep[10] - # showing 10 of 11 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 10 of 11 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -25,7 +25,7 @@ variable mean median sd mad q5 q95 y_rep[1] - # showing 1 of 11 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 1 of 11 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -44,7 +44,7 @@ y_rep[9] y_rep[10] - # showing 10 of 11 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 10 of 11 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -55,7 +55,7 @@ y_rep[1] y_rep[2] - # showing 2 of 11 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 2 of 11 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -84,7 +84,7 @@ y_rep[1] y_rep[2] - # showing 2 of 10 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 2 of 10 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- diff --git a/tests/testthat/_snaps/fit-laplace.md b/tests/testthat/_snaps/fit-laplace.md index 4effe964d..3bdb292e5 100644 --- a/tests/testthat/_snaps/fit-laplace.md +++ b/tests/testthat/_snaps/fit-laplace.md @@ -19,5 +19,5 @@ variable mean median sd mad q5 q95 lp__ - # showing 1 of 6 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 1 of 6 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) diff --git a/tests/testthat/_snaps/fit-mcmc.md b/tests/testthat/_snaps/fit-mcmc.md index f648f94cb..11e932fc4 100644 --- a/tests/testthat/_snaps/fit-mcmc.md +++ b/tests/testthat/_snaps/fit-mcmc.md @@ -18,7 +18,7 @@ variable mean median sd mad q5 q95 rhat ess_bulk ess_tail lp__ - # showing 1 of 5 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 1 of 5 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -49,7 +49,7 @@ theta_raw[6] theta_raw[7] - # showing 10 of 19 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 10 of 19 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -60,7 +60,7 @@ lp__ mu - # showing 2 of 19 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 2 of 19 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -97,7 +97,7 @@ theta[1] theta[2] - # showing 2 of 8 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 2 of 8 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -131,5 +131,5 @@ fit_mcmc$save_metric_files() Condition Error: - ! No metric files found. Make sure to set 'save_metric=TRUE' when fitting the model. + ! No metric files found. Make sure to set `save_metric = TRUE` when fitting the model. diff --git a/tests/testthat/_snaps/fit-mle.md b/tests/testthat/_snaps/fit-mle.md index 2e5b14e6e..4bf685fcd 100644 --- a/tests/testthat/_snaps/fit-mle.md +++ b/tests/testthat/_snaps/fit-mle.md @@ -18,5 +18,5 @@ variable estimate lp__ - # showing 1 of 5 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 1 of 5 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) diff --git a/tests/testthat/_snaps/fit-vb.md b/tests/testthat/_snaps/fit-vb.md index cfd3a7039..c0cefb75c 100644 --- a/tests/testthat/_snaps/fit-vb.md +++ b/tests/testthat/_snaps/fit-vb.md @@ -19,7 +19,7 @@ variable mean median sd mad q5 q95 lp__ - # showing 1 of 6 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 1 of 6 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -38,7 +38,7 @@ theta_raw[5] theta_raw[6] - # showing 10 of 20 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 10 of 20 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) --- @@ -84,5 +84,5 @@ tau lp__ - # showing 10 of 11 rows (change via 'max_rows' argument or 'cmdstanr_max_rows' option) + # showing 10 of 11 rows (change via `max_rows` argument or `cmdstanr_max_rows` option) diff --git a/tests/testthat/_snaps/install.md b/tests/testthat/_snaps/install.md index 1297ba0d1..782c7e607 100644 --- a/tests/testthat/_snaps/install.md +++ b/tests/testthat/_snaps/install.md @@ -4,7 +4,7 @@ check_cmdstan_toolchain(fix = TRUE, quiet = TRUE) Condition Warning: - The 'fix' argument is deprecated as of CmdStanR 1.0.0 and will be removed in a future release. + The `fix` argument is deprecated as of CmdStanR 1.0.0 and will be removed in a future release. # toolchain_PATH_env_var() rejects unsafe toolchain paths diff --git a/tests/testthat/_snaps/threads.md b/tests/testthat/_snaps/threads.md index 433a91ffd..792862fd0 100644 --- a/tests/testthat/_snaps/threads.md +++ b/tests/testthat/_snaps/threads.md @@ -4,5 +4,5 @@ invisible(do.call(mod$pathfinder, pathfinder_args)) Condition Warning: - 'num_threads' is deprecated as of CmdStanR 1.0.0 and will be removed in a future release. Please use 'threads' instead. + `num_threads` is deprecated as of CmdStanR 1.0.0 and will be removed in a future release. Please use `threads` instead. diff --git a/tests/testthat/test-build-info.R b/tests/testthat/test-build-info.R index c238063f1..a27dc8ec2 100644 --- a/tests/testthat/test-build-info.R +++ b/tests/testthat/test-build-info.R @@ -436,7 +436,7 @@ test_that("stan_build_info() errors on unusable paths and unidentifiable executa expect_error( stan_build_info(failed_exe), paste0( - "Running '", resolve_path(failed_exe), "' with the argument 'info' did ", + "Running '", resolve_path(failed_exe), "' with the argument `info` did ", "not report a ", "Stan version, so it is either not a CmdStan executable or cannot be ", "run." @@ -452,7 +452,7 @@ test_that("stan_build_info() errors on unusable paths and unidentifiable executa expect_error( stan_build_info(no_version_exe), paste0( - "Running '", resolve_path(no_version_exe), "' with the argument 'info' ", + "Running '", resolve_path(no_version_exe), "' with the argument `info` ", "did not report a Stan version, so it is either not a CmdStan ", "executable or cannot be run." ), diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index 2392a53d4..a1a0df46b 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -67,7 +67,7 @@ test_that("process_fitted_params() works with basic input types", { test_that("process_fitted_params() errors with bad args", { error_msg <- paste0( - "'fitted_params' must be a list of paths to CSV files, a CmdStanMCMC, ", + "`fitted_params` must be a list of paths to CSV files, a CmdStanMCMC, ", "CmdStanMLE, CmdStanLaplace, CmdStanVB, or CmdStanPathfinder object, ", "a posterior::draws_array or a posterior::draws_matrix." ) diff --git a/tests/testthat/test-fit-shared.R b/tests/testthat/test-fit-shared.R index d5a65bc9f..ec132c64a 100644 --- a/tests/testthat/test-fit-shared.R +++ b/tests/testthat/test-fit-shared.R @@ -53,7 +53,7 @@ test_that("saving diagnostic csv output works", { if (!(method %in% c("sample", "variational"))) { expect_error( fit$save_latent_dynamics_files(), - "No latent dynamics files found. Set 'save_latent_dynamics=TRUE' when fitting the model", + "No latent dynamics files found. Set `save_latent_dynamics = TRUE` when fitting the model", fixed = TRUE ) next @@ -136,7 +136,7 @@ test_that("draws() method returns a 'draws' object", { if (method != "sample") { expect_warning( fit$draws(inc_warmup = TRUE), - "'inc_warmup' is ignored except when used with CmdStanMCMC objects" + "`inc_warmup` is ignored except when used with CmdStanMCMC objects" ) } } @@ -613,7 +613,7 @@ test_that("code() warns if model not created with Stan file", { ) expect_warning( expect_null(fit_exe$code()), - "'$code()' will return NULL because the 'CmdStanModel' was not created with a Stan file", + "`$code()` will return NULL because the `CmdStanModel` was not created with a Stan file", fixed = TRUE ) }) diff --git a/tests/testthat/test-install.R b/tests/testthat/test-install.R index 177eb8e88..8efb45440 100644 --- a/tests/testthat/test-install.R +++ b/tests/testthat/test-install.R @@ -46,10 +46,10 @@ test_that("install_cmdstan() errors if it times out", { expect_message( install_cmdstan(dir = dir, timeout = 1, quiet = TRUE, overwrite = dir_exists, cores = CORES, wsl = os_is_wsl()), - if (dir_exists) "* Removing the existing installation" else "* * Installing CmdStan from https://github.com", + if (dir_exists) "* Removing the existing installation" else paste0("* Installing CmdStan v", ver, " in"), fixed = TRUE ), - "increasing the value of the 'timeout' argument and running again with 'quiet=FALSE'", + "increasing the value of the `timeout` argument and running again with `quiet = FALSE`", fixed = TRUE ) dir_exists <- dir.exists(file.path(dir, paste0("cmdstan-",ver))) @@ -58,10 +58,10 @@ test_that("install_cmdstan() errors if it times out", { expect_message( install_cmdstan(dir = dir, timeout = 1, quiet = FALSE, overwrite = dir_exists, cores = CORES, wsl = os_is_wsl()), - if (dir_exists) "* Removing the existing installation" else "* * Installing CmdStan from https://github.com", + if (dir_exists) "* Removing the existing installation" else paste0("* Installing CmdStan v", ver, " in"), fixed = TRUE ), - "Try increasing the value of the 'timeout' argument.", + "Try increasing the value of the `timeout` argument.", fixed = TRUE ) }) @@ -124,11 +124,11 @@ test_that("toolchain checks on Unix work", { skip_if(os_is_windows()) withr::local_envvar(c("PATH" = "")) if (os_is_macos()) { - err_msg_cpp <- "A suitable C++ compiler was not found. Please install the command line tools for Mac with 'xcode-select --install' or install Xcode from the app store. Then restart R and run cmdstanr::check_cmdstan_toolchain()." - err_msg_make <- "The 'make' tool was not found. Please install the command line tools for Mac with 'xcode-select --install' or install Xcode from the app store. Then restart R and run cmdstanr::check_cmdstan_toolchain()." + err_msg_cpp <- "A suitable C++ compiler was not found. Please install the command line tools for Mac with `xcode-select --install` or install Xcode from the app store. Then restart R and run cmdstanr::check_cmdstan_toolchain()." + err_msg_make <- "The make tool was not found. Please install the command line tools for Mac with `xcode-select --install` or install Xcode from the app store. Then restart R and run cmdstanr::check_cmdstan_toolchain()." } else { - err_msg_cpp <- "A C++ compiler was not found. Please install the 'clang++' or 'g++' compiler, restart R, and run cmdstanr::check_cmdstan_toolchain()." - err_msg_make <- "The 'make' tool was not found. Please install 'make', restart R, and then run cmdstanr::check_cmdstan_toolchain()." + err_msg_cpp <- "A C++ compiler was not found. Please install the clang++ or g++ compiler, restart R, and run cmdstanr::check_cmdstan_toolchain()." + err_msg_make <- "The make tool was not found. Please install make, restart R, and then run cmdstanr::check_cmdstan_toolchain()." } expect_error( check_unix_cpp_compiler(), diff --git a/tests/testthat/test-json.R b/tests/testthat/test-json.R index 36527f54f..ca748334e 100644 --- a/tests/testthat/test-json.R +++ b/tests/testthat/test-json.R @@ -113,7 +113,7 @@ test_that("write_stan_json errors if NULL variables", { test_that("write_stan_json() errors if data is not a list", { expect_error( write_stan_json(1:10), - "'data' must be a list" + "`data` must be a list" ) }) @@ -266,17 +266,17 @@ test_that("write_stan_json() errors if data frame has columns of invalid type", test_that("write_stan_json() errors if bad names", { expect_error( write_stan_json(list(x = 1, y = 2, x = 3), file = tempfile()), - "Duplicate names not allowed in 'data'" + "Duplicate names not allowed in `data`" ) expect_error( write_stan_json(list(1, 2), tempfile()), - "All elements in 'data' list must have names" + "All elements in `data` list must have names" ) expect_error( write_stan_json(list(a = 1, 2), tempfile()), - "All elements in 'data' list must have names" + "All elements in `data` list must have names" ) }) diff --git a/tests/testthat/test-model-code-print.R b/tests/testthat/test-model-code-print.R index 341be7bbd..be4418165 100644 --- a/tests/testthat/test-model-code-print.R +++ b/tests/testthat/test-model-code-print.R @@ -64,12 +64,12 @@ test_that("code() warns and print() errors if only exe and no Stan file", { mod_exe <- cmdstan_model(exe_file = mod$exe_file()) expect_warning( expect_null(mod_exe$code()), - "'$code()' will return NULL because the 'CmdStanModel' was not created with a Stan file", + "`$code()` will return NULL because the `CmdStanModel` was not created with a Stan file", fixed = TRUE ) expect_error( mod_exe$print(), - "'$print()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", + "`$print()` cannot be used because the `CmdStanModel` was not created with a Stan file.", fixed = TRUE ) }) @@ -78,7 +78,7 @@ test_that("check_syntax() errors if only exe and no Stan file", { mod_exe <- cmdstan_model(exe_file = mod$exe_file()) expect_error( mod_exe$check_syntax(), - "'$check_syntax()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", + "`$check_syntax()` cannot be used because the `CmdStanModel` was not created with a Stan file.", fixed = TRUE ) }) diff --git a/tests/testthat/test-model-compile.R b/tests/testthat/test-model-compile.R index 2a3b9192e..d48e67443 100644 --- a/tests/testthat/test-model-compile.R +++ b/tests/testthat/test-model-compile.R @@ -282,17 +282,17 @@ test_that("compiling stops on hyphens in stanc_options", { stan_file <- testing_stan_file("bernoulli") expect_error( cmdstan_model(stan_file, stanc_options = hyphens), - "No leading hyphens allowed in stanc options (--allow-undefined). Use options without leading hyphens, for example `stanc_options = list('warn-uninitialized')`", + "No leading hyphens allowed in stanc options (--allow-undefined). Use options without leading hyphens, for example `stanc_options = list(\"warn-uninitialized\")`", fixed = TRUE ) expect_error( cmdstan_model(stan_file, stanc_options = hyphens2), - "No leading hyphens allowed in stanc options (--allow-undefined). Use options without leading hyphens, for example `stanc_options = list('warn-uninitialized')`", + "No leading hyphens allowed in stanc options (--allow-undefined). Use options without leading hyphens, for example `stanc_options = list(\"warn-uninitialized\")`", fixed = TRUE ) expect_error( cmdstan_model(stan_file, stanc_options = hyphens3), - "No leading hyphens allowed in stanc options (--o). Use options without leading hyphens, for example `stanc_options = list('warn-uninitialized')`", + "No leading hyphens allowed in stanc options (--o). Use options without leading hyphens, for example `stanc_options = list(\"warn-uninitialized\")`", fixed = TRUE ) }) @@ -455,7 +455,7 @@ test_that("check_syntax() works", { mod_exe <- cmdstan_model(exe_file = mod_removed_stan_file$exe_file()) expect_error( mod_exe$check_syntax(), - "'$check_syntax()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", + "`$check_syntax()` cannot be used because the `CmdStanModel` was not created with a Stan file.", fixed = TRUE ) @@ -739,17 +739,17 @@ test_that("a model created only with exe_file refuses what needs a Stan file", { mod_exe <- cmdstan_model(exe_file = mod$exe_file()) expect_error( mod_exe$check_syntax(), - "'$check_syntax()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", + "`$check_syntax()` cannot be used because the `CmdStanModel` was not created with a Stan file.", fixed = TRUE ) expect_error( mod_exe$variables(), - "'$variables()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", + "`$variables()` cannot be used because the `CmdStanModel` was not created with a Stan file.", fixed = TRUE ) expect_error( mod_exe$hpp_file(), - "'$hpp_file()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", + "`$hpp_file()` cannot be used because the `CmdStanModel` was not created with a Stan file.", fixed = TRUE ) }) @@ -757,7 +757,7 @@ test_that("a model created only with exe_file refuses what needs a Stan file", { test_that("cmdstan_model errors with no args ", { expect_error( cmdstan_model(), - "Unable to create a `CmdStanModel` object. Both 'stan_file' and 'exe_file' are undefined.", + "Unable to create a `CmdStanModel` object. Both `stan_file` and `exe_file` are undefined.", fixed = TRUE ) }) @@ -911,7 +911,7 @@ test_that("format() works", { mod_exe <- cmdstan_model(exe_file = mod_removed_stan_file$exe_file()) expect_error( mod_exe$format(), - "'$format()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", + "`$format()` cannot be used because the `CmdStanModel` was not created with a Stan file.", fixed = TRUE ) }) diff --git a/tests/testthat/test-model-init.R b/tests/testthat/test-model-init.R index c82d79761..a7db0266a 100644 --- a/tests/testthat/test-model-init.R +++ b/tests/testthat/test-model-init.R @@ -50,13 +50,13 @@ test_that("sample method works with valid numeric init values", { test_that("fitting methods throw errors for invalid init arguments", { expect_error( mod$sample(data = data_list, chains = 2, init = -10, seed = 123), - "If 'init' is numeric it must be a single real number >= 0", + "If `init` is numeric it must be a single real number >= 0", fixed = TRUE ) expect_error( mod$sample(data = data_list, init = data.frame(x = 10)), - "Invalid 'init' specification", + "Invalid `init` specification", fixed = TRUE ) @@ -137,13 +137,13 @@ test_that("error if init list is specified incorrectly", { init_list <- list(alpha = 1, beta = c(1,1)) expect_error( mod_logistic$sample(data = data_list_logistic, chains = 2, init = init_list), - "If 'init' is a list it must be a list of lists" + "If `init` is a list it must be a list of lists" ) init_list <- list(init_list) expect_error( mod_logistic$sample(data = data_list_logistic, chains = 2, init = init_list), - "'init' has the wrong length" + "`init` has the wrong length" ) init_list <- list( @@ -152,13 +152,13 @@ test_that("error if init list is specified incorrectly", { ) expect_error( mod_logistic$optimize(data = data_list_logistic, init = init_list, seed = 123), - "'init' has the wrong length" + "`init` has the wrong length" ) init_list <- list(list(), list()) expect_error( mod_logistic$sample(data = data_list_logistic, chains = 2, init = init_list), - "'init' contains empty lists." + "`init` contains empty lists." ) init_list <- list() @@ -170,7 +170,7 @@ test_that("error if init list is specified incorrectly", { init_list[[2]] = init_list[[1]] expect_error( mod_logistic$sample(data = data_list_logistic, chains = 2, init = init_list), - "'init' contains entries with parameter names that include square-brackets, which is not permitted." + "`init` contains entries with parameter names that include square-brackets, which is not permitted." ) }) @@ -253,7 +253,7 @@ test_that("init function return value is validated for each init", { } expect_error( process_init(init_fun, num_procs = 2), - "If 'init' is a function it must return a single list" + "If `init` is a function it must return a single list" ) }) @@ -261,7 +261,7 @@ test_that("error if init function specified incorrectly", { init_fun <- function(a, b) list(a, b) expect_error( mod_logistic$sample(data = data_list_logistic, chains = 2, init = init_fun), - "If 'init' is a function it must have zero arguments or only argument 'chain_id'" + "If `init` is a function it must have zero arguments or only argument `chain_id`" ) init_fun <- function() { @@ -269,7 +269,7 @@ test_that("error if init function specified incorrectly", { } expect_error( mod_logistic$sample(data = data_list_logistic, chains = 2, init = init_fun), - "If 'init' is a function it must return a single list" + "If `init` is a function it must return a single list" ) init_fun <- function() { @@ -277,13 +277,13 @@ test_that("error if init function specified incorrectly", { } expect_error( mod_logistic$sample(data = data_list_logistic, chains = 2, init = init_fun), - "If 'init' is a function it must return a single list" + "If `init` is a function it must return a single list" ) init_fun <- function() list() expect_error( mod_logistic$sample(data = data_list_logistic, chains = 1, init = init_fun), - "'init' contains empty lists." + "`init` contains empty lists." ) }) diff --git a/tests/testthat/test-model-laplace.R b/tests/testthat/test-model-laplace.R index 213f36b73..064b0d015 100644 --- a/tests/testthat/test-model-laplace.R +++ b/tests/testthat/test-model-laplace.R @@ -127,7 +127,7 @@ test_that("laplace() errors if jacobian arg doesn't match what optimize used", { ) expect_error( mod$laplace(data = data_list, mode = fit, jacobian = TRUE), - "'jacobian' argument to optimize and laplace must match" + "`jacobian` argument to optimize and laplace must match" ) expect_error( mod$laplace(data = data_list, mode = fit, jacobian = TRUE), @@ -141,11 +141,11 @@ test_that("laplace() errors with bad combinations of arguments", { ) expect_error( mod$laplace(data = data_list, mode = mod, opt_args = list(iter = 10)), - "Cannot specify both 'opt_args' and 'mode' arguments." + "Cannot specify both `opt_args` and `mode` arguments." ) expect_error( mod$laplace(data = data_list, mode = rnorm(10)), - "If not NULL or a CmdStanMLE object then 'mode' must be a path to a CSV file" + "If not NULL or a CmdStanMLE object then `mode` must be a path to a CSV file" ) }) diff --git a/tests/testthat/test-model-methods.R b/tests/testthat/test-model-methods.R index 94b6b4f93..533f99bd7 100644 --- a/tests/testthat/test-model-methods.R +++ b/tests/testthat/test-model-methods.R @@ -293,7 +293,7 @@ test_that("unconstrain_draws returns correct values", { expect_equal(as.numeric(x_draws), as.numeric(unconstrained_draws)) expect_message(fit$unconstrain_draws(draws = fit$draws(), inc_warmup = TRUE), - "'inc_warmup' cannot be used with a draws object. Ignoring.") + "`inc_warmup` cannot be used with a draws object. Ignoring.") # With a lower-bounded constraint, the parameter draws should be the # exponentiation of the unconstrained draws diff --git a/tests/testthat/test-model-optimize.R b/tests/testthat/test-model-optimize.R index 658052c01..ff6183a33 100644 --- a/tests/testthat/test-model-optimize.R +++ b/tests/testthat/test-model-optimize.R @@ -73,7 +73,7 @@ test_that("optimize() errors with bad combination of arguments", { # for all similar args because of how it's implemented) expect_error( mod$optimize(data = data_list, algorithm = "newton", tol_grad = 0.1), - "'tol_grad' can't be used when algorithm is 'newton'" + "`tol_grad` can't be used when algorithm is `\"newton\"`" ) expect_error( mod$optimize(data = data_list, algorithm = "bfgs", tol_obj = -10), @@ -81,17 +81,17 @@ test_that("optimize() errors with bad combination of arguments", { ) expect_error( mod$optimize(data = data_list, init_alpha = 0.1), - "Please specify 'algorithm' in order to use 'init_alpha'" + "Please specify `algorithm` in order to use `init_alpha`" ) # history size only allowed with lbfgs and must be positive integer expect_error( mod$optimize(data = data_list, history_size = 1), - "'history_size' is only allowed if 'algorithm' is specified as 'lbfgs'" + "`history_size` is only allowed if `algorithm` is specified as `\"lbfgs\"`" ) expect_error( mod$optimize(data = data_list, algorithm = "bfgs", history_size = 1), - "'history_size' is only allowed if 'algorithm' is specified as 'lbfgs'" + "`history_size` is only allowed if `algorithm` is specified as `\"lbfgs\"`" ) expect_error( mod$optimize(data = data_list, algorithm = "lbfgs", history_size = 1.5), diff --git a/tests/testthat/test-model-variables.R b/tests/testthat/test-model-variables.R index 62d24aff7..5efa6c6fe 100644 --- a/tests/testthat/test-model-variables.R +++ b/tests/testthat/test-model-variables.R @@ -137,7 +137,7 @@ test_that("$variables() errors when the model was not created from a Stan file", mod_exe <- cmdstan_model(exe_file = mod$exe_file()) expect_error( mod_exe$variables(), - "'$variables()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", + "`$variables()` cannot be used because the `CmdStanModel` was not created with a Stan file.", fixed = TRUE ) }) diff --git a/tests/testthat/test-path.R b/tests/testthat/test-path.R index bae7c3f95..f623fab33 100644 --- a/tests/testthat/test-path.R +++ b/tests/testthat/test-path.R @@ -98,7 +98,7 @@ test_that("Existing CMDSTAN env path with no install resets cached state", { withr::local_envvar(c(CMDSTAN = empty_parent)) expect_warning( cmdstanr_initialize(), - "CmdStan path not set. No CmdStan installation found in the path specified by the environment variable 'CMDSTAN'.", + "CmdStan path not set. No CmdStan installation found in the path specified by the environment variable `CMDSTAN`.", fixed = TRUE ) expect_null(.cmdstanr$PATH) diff --git a/tests/testthat/test-threads.R b/tests/testthat/test-threads.R index 062356d83..f2761ca8f 100644 --- a/tests/testthat/test-threads.R +++ b/tests/testthat/test-threads.R @@ -142,7 +142,7 @@ test_that("threading works with pathfinder()", { pathfinder_args$num_threads <- 2 expect_error( do.call(mod$pathfinder, pathfinder_args), - "Cannot specify both 'threads' and deprecated 'num_threads'" + "Cannot specify both `threads` and deprecated `num_threads`" ) pathfinder_args$threads <- NULL pathfinder_args$show_messages <- FALSE diff --git a/vignettes/cmdstanr-internals.Rmd b/vignettes/cmdstanr-internals.Rmd index 96fb05d48..5de30c55e 100644 --- a/vignettes/cmdstanr-internals.Rmd +++ b/vignettes/cmdstanr-internals.Rmd @@ -133,7 +133,7 @@ in the Stan User's Guide. Pedantic mode is available when compiling the model or when using the separate `$check_syntax()` method of a `CmdStanModel` object. Internally this corresponds -to setting the `stanc` (Stan transpiler) option `warn-pedantic`. Here we +to setting the stanc (Stan transpiler) option `warn-pedantic`. Here we demonstrate pedantic mode with a Stan program that is syntactically correct but is missing a lower bound and a prior for a parameter.