Skip to content

Commit

Permalink
formally documented magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
gowerc committed Feb 5, 2024
1 parent 38ee15f commit 730ed0a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Collate:
'DataLongitudinal.R'
'DataSurvival.R'
'DataJoint.R'
'constants.R'
'StanModule.R'
'Prior.R'
'Parameter.R'
Expand Down
4 changes: 3 additions & 1 deletion R/JointModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @include LongitudinalModel.R
#' @include SurvivalModel.R
#' @include Link.R
#' @include constants.R
NULL


Expand Down Expand Up @@ -161,7 +162,8 @@ sampleStanModel.JointModel <- function(object, data, ...) {
args[["chains"]] <- if ("chains" %in% names(args)) {
args[["chains"]]
} else {
4
# Magic constant from R/constants.R
CMDSTAN_DEFAULT_CHAINS
}

initial_values <- if ("init" %in% names(args)) {
Expand Down
14 changes: 14 additions & 0 deletions R/constants.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@



# This file defines any magic numbers or constants used in the package.

# The default number of chains to use when sampling from a Stan model.
# This is the default set by the `cmdstanr` package however we need to fix it
# as if they were to change it it would break our code as we create the number
# of initial values based on this number.
#
# Unfortunately the default value is in a method of an unexported object (only the constructor
# is exported) so there is no way for us to access it without digging through the
# internals of `cmdstanr`.
CMDSTAN_DEFAULT_CHAINS <- 4

0 comments on commit 730ed0a

Please sign in to comment.