Learn R Programming

ss3sim (version 0.9.0)

change_year: Methods to change the years in an ss3sim model

Description

change_year takes SS3 .ctl, .dat, .par, starter.ss, and .forecast files and changes the start and end year of the model. change_year works with ss3sim operating or estimation models.

Usage

change_year(year_begin = 1, year_end = 100, burnin = 0,
  ctl_file_in = NULL, ctl_file_out = "new.ctl", dat_file_in = NULL,
  dat_file_out = "new.dat", par_file_in = NULL, par_file_out = "new.ss",
  str_file_in = NULL, str_file_out = "starter.ss", for_file_in = NULL,
  for_file_out = "forecast.ss", verbose = FALSE)

Arguments

year_begin
Desired start year
year_end
Desired end year
burnin
Length of burnin period. Default is zero for an OM. Use burnin for EM models, to establish a period with no fishing. Note that the value should correspond to the number of years, not a year value.
ctl_file_in
A string providing the path to the input SS3 .ctl file.
ctl_file_out
Output SS3 control file, if NULL the file will be named the same as the ctl_file_in
dat_file_in
A string providing the path to the input SS3 .dat file.
dat_file_out
Output SS3 data file, if NULL the file will be named the same as the dat_file_in
par_file_in
A string providing the path to the input SS3 .par file.
par_file_out
Output SS3 parameter file, if NULL the file will be named the same as the par_file_in
str_file_in
A string providing the path to the input SS3 starter.ss file.
str_file_out
Output SS3 starter file, if NULL the file will be named the same as the str_file_in
for_file_in
Input SS3 forecast file
for_file_out
Output SS3 forecast file, if NULL the file will be named the same as the for_file_in
verbose
Logical argument that is passed on to internal calls to r4ss functions for reading and writing SS3 files. Setting verbose to TRUE may be useful for troubleshooting.

Value

  • The function creates modified versions of the .par, .dat, .ctl, .starter, and .forecast files.

Details

Operating models and estimation models will not have all of the same files, thus if the file does not exist change the _file_in to NULL. The code will add data for all years specified, minus the burnin period, if the data type is present in the dat_file_in file. The manipulation performed on the dat_file_in file is not complete and users will need to specify data for years which are deleted. The function removes all composition data except for the first year. To remove data use sample_index, sample_lcomp, or sample_agecomp. For models that use the .forecast file, all references to years must be made with relative values (i.e., 0 or negative integers).

Examples

Run this code
# Create a temporary folder for the output and set the working directory:
wd.old <- getwd()
temp_path <- file.path(tempdir(), "change_year-example")
dir.create(temp_path, showWarnings = FALSE)
setwd(temp_path)

# Find the SS3 "Simple" model in the package data:
d <- system.file("extdata", package = "ss3sim")
simple <- paste0(d, "/Simple")
dir.create("Simple")
file.copy(simple, ".", recursive = TRUE)
setwd("Simple")

# Run SS3 to create control.ss_new and Report.sso:
system("SS3_24o_safe starter.ss -noest")

change_year(year_begin = 1, year_end = 100, burnin = 25,
 ctl_file_in = "control.ss_new", ctl_file_out = "change_year.ctl",
 dat_file_in = "simple.dat", dat_file_out = "change_year.dat",
 par_file_in = "ss3.par", par_file_out = "change_year.par",
 str_file_in = "starter.ss", str_file_out = "change_year_starter.ss",
 for_file_in = "forecast.ss", for_file_out = "change_year_forecast.ss")

# Clean up:
setwd("../")
unlink("Simple")
setwd(wd.old)

Run the code above in your browser using DataLab