diff --git a/DESCRIPTION b/DESCRIPTION index 9de8240..e958ad6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mse Title: Tools for Running Management Strategy Evaluations using FLR -Version: 2.4.8.9011 +Version: 2.4.9 Authors@R: c(person(given = "Iago", family = "Mosqueira", role = c("aut", "cre"), email = "iago.mosqueira@wur.nl"), person("Ernesto", "Jardim", email = "ernesto.jardim@gmail.com", diff --git a/NAMESPACE b/NAMESPACE index 76431c4..5c945f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -126,6 +126,7 @@ exportClasses( exportMethods( "[", + "append", "args", "args<-", "biol", diff --git a/NEWS.md b/NEWS.md index 5ab8895..ae2d4d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# mse 2.5.0 + +## NEW FEATURES + +- `append(FLombf, FLombf, after)` method to join two operating models at a year boundary. + # mse 2.4.9 ## BUG FIXES diff --git a/R/FLombf-class.R b/R/FLombf-class.R index 94dbed3..545b5e4 100644 --- a/R/FLombf-class.R +++ b/R/FLombf-class.R @@ -864,6 +864,60 @@ setMethod("combine", signature(x = "FLombf", y = "FLombf"), function(x, y, ...){ }) # }}} +# append {{{ + +#' Append two FLombf objects along the year dimension +#' +#' Joins two \code{FLombf} objects along the year axis: the first object is +#' windowed to \code{after}, and the second from \code{after + 1} to its last +#' year. The two windowed pieces are then combined using \code{FLCore::append} +#' on the underlying \code{FLBiols} and \code{FLFisheries} slots. +#' +#' @param x An \code{FLombf} object, used up to year \code{after}. +#' @param values An \code{FLombf} object, used from year \code{after + 1}. +#' @param after Integer year. The last year taken from \code{x}. Defaults to +#' the last year of \code{x}. +#' +#' @return A new \code{FLombf} object spanning the years of \code{x} up to +#' \code{after} joined with the years of \code{values} from \code{after + 1}. +#' +#' @examples +#' # Split an FLombf at year 2020 and re-join +#' om1 <- window(om, end=2020) +#' om2 <- window(om, start=2021) +#' om3 <- append(om1, om2, after=2020) +#' +#' @rdname FLombf-class +#' @aliases append,FLombf,FLombf-method + +setMethod("append", signature(x="FLombf", values="FLombf"), + function(x, values, after=dims(x)$maxyear) { + + after <- as.integer(after) + + # WINDOW x up to 'after' + x <- window(x, end=after) + + # WINDOW values from 'after + 1' + values <- window(values, start=after + 1L) + + # APPEND biols + biols(x) <- FLBiols(Map(append, x=biols(x), values=biols(values))) + + # APPEND fisheries: each FLFishery, then each FLCatch within + fisheries(x) <- FLFisheries(Map(function(fx, fv) { + # APPEND the FLFishery-level slots (effort, etc.) + out <- append(fx, fv) + # APPEND every FLCatch within the fishery + out@.Data <- Map(append, x=fx@.Data, values=fv@.Data) + names(out) <- names(fx) + return(out) + }, fx=fisheries(x), fv=fisheries(values))) + + return(x) + } +) # }}} + # deviances {{{ setMethod("deviances", signature(object="FLombf"), diff --git a/README.md b/README.md index c76b1a3..b430cc2 100644 --- a/README.md +++ b/README.md @@ -33,5 +33,5 @@ You are welcome to: - Submit suggestions and bug-reports at: - Send a pull request on: -- Authors: Iago Mosqueira, WUR. Ernesto Jardim, IPMA. +- Authors: Iago Mosqueira, WMR. Ernesto Jardim, IPMA. - Maintainer: Iago Mosqueira, WMR.