Skip to content

Commit 19a132d

Browse files
committed
Improved defaults can now be implemented while keeping backwards compatibility via defaults_edition().
1 parent c72c8d8 commit 19a132d

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Collate:
9797
'manipulate_species.R'
9898
'calibrate.R'
9999
'match.R'
100+
'defaults_edition.R'
100101
RoxygenNote: 7.2.0
101102
Roxygen: list(markdown = TRUE)
102103
Encoding: UTF-8

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export(constantRDD)
4040
export(constant_other)
4141
export(customFunction)
4242
export(default_pred_kernel_params)
43+
export(defaults_edition)
4344
export(distanceMaxRelRDI)
4445
export(distanceSSLogN)
4546
export(double_sigmoid_length)

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# mizer (development version)
22

3+
* Improved defaults can now be implemented while keeping backwards compatibility
4+
via `defaults_edition()`.
35
* The entries of the interaction matrix and of interaction_resource are not
46
longer restricted to be less or equal to 1. #232
57
* If user supplies no row names in the interaction matrix but give column names

R/defaults_edition.R

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#' Default editions
2+
#'
3+
#' Function to set and get which edition of default choices is being used.
4+
#'
5+
#' The mizer functions for creating new models make a lot of choices for default
6+
#' values for parameters that are not provided by the user. Sometimes we find
7+
#' better ways to choose the defaults and update mizer accordingly. When we do
8+
#' this, we will increase the edition number.
9+
#'
10+
#' If you call `defaults_edition()` without an argument it returns the
11+
#' currently active edition. Otherwise it sets the active edition to the
12+
#' given value.
13+
#'
14+
#' Users who want their existing code for creating models not to change
15+
#' behaviour when run with future versions of mizer should explicitly set the
16+
#' desired defaults edition at the top of their code.
17+
#'
18+
#' The most recent edition is edition 2. It will become the default in the
19+
#' next release. The current default is edition 1. The following defaults
20+
#' are changed in edition 2:
21+
#'
22+
#' * catchability = 0.3 instead of 1
23+
#' * initial effort = 1 instead of 0
24+
#'
25+
#' @param edition NULL or a numerical value.
26+
#' @return The current edition number.
27+
#' @export
28+
defaults_edition <- function(edition = NULL) {
29+
current_edition <- 1
30+
# if called without argument or with NULL, return the current edition
31+
if (is.null(edition)) {
32+
edition <- getOption("mizer_defaults_edition")
33+
return(ifelse(is.null(edition), current_edition, edition))
34+
}
35+
# else check validity and set option
36+
assert_that(is.numeric(edition),
37+
edition >= 1)
38+
options(mizer_defaults_edition = edition)
39+
message("Mizer parameter defaults are now at edition ", edition, ".")
40+
return(invisible(edition))
41+
}

man/defaults_edition.Rd

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgdown/_pkgdown.yml

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ reference:
9090
- newTraitParams
9191
- newMultispeciesParams
9292
- mizer-package
93+
- defaults_edition
9394
- title: Changing model parameters
9495
description: Even after you have created a model, you can still make changes
9596
with the following functions. This is useful while tuning the model and for

0 commit comments

Comments
 (0)