This function replaces the recruitment deviations in the
control file of a Stock Synthesis model with those specified in the argument
recdevs
. The new control file is then written to the disk if
ctl_file_out
is specified.
It is imperative that the path provided in ctl_file_in
be to a ss_new
file so change_rec_devs
can
properly determine where to place the recruitment deviations
in the control file.
change_rec_devs(recdevs, ctl_file_in, ctl_file_out = "control_recruitment.ss")
A vector of recruitment deviations to be entered into
the Stock Synthesis control file. The vector must be the same length as the vector
of recruitment deviations that are commented out in the ss_new
control file. This vector can be found by searching for
# all recruitment deviations
within the file.
If a single value is provided instead of a vector, the value
will be repeated for every recruitment deviation in the model.
Alternatively, users can supply a named vector with each name being a year
of the model. Missing years will be filled in with values of zero.
A string providing the path to the input Stock Synthesis .ctl
file.
A string providing the path to the output Stock Synthesis control file. If the value is NULL
, the file will not be written to the disk.
A modified Stock Synthesis control file.
d <- system.file(file.path("extdata", "models"), package = "ss3sim")
change_rec_devs(
recdevs = rlnorm(101),
ctl_file_in = file.path(d, "cod-om", "codOM.ctl"),
ctl_file_out = file.path(tempdir(), "control_recdevs.ss")
)
# Change the recruitment deviations in years 2:11
change_rec_devs(
recdevs = stats::setNames(rlnorm(10), 2:11),
ctl_file_in = file.path(d, "cod-om", "codOM.ctl"),
ctl_file_out = file.path(tempdir(), "control_recdevsInitial.ss")
)
lapply(
X = dir(tempdir(), pattern = "control_.+ss", full.names = TRUE),
FUN = unlink
)
#> [[1]]
#> [1] 0
#>
#> [[2]]
#> [1] 0
#>