Skip to content

Add append method for FLombf to join two OMs at a year boundary#45

Merged
iagomosqueira merged 6 commits into
develfrom
copilot/add-append-method-to-flombf
Jun 4, 2026
Merged

Add append method for FLombf to join two OMs at a year boundary#45
iagomosqueira merged 6 commits into
develfrom
copilot/add-append-method-to-flombf

Conversation

Copilot AI commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

FLombf lacked an append method, making it impossible to splice two operating models along the year axis (e.g. after running a simulation in pieces).

Changes

  • R/FLombf-class.R — New setMethod("append", signature(x="FLombf", values="FLombf")):
    • Windows x up to after (default: dims(x)$maxyear) and values from after + 1
    • Appends biols via FLBiols(Map(append, x=biols(x), values=biols(values)))
    • Appends fisheries by chaining append on each FLFishery (effort etc.) then on each FLCatch within it
  • NAMESPACE — Added "append" to exportMethods()
  • NEWS.md — Documented under new version 2.5.0

Usage

om1 <- window(om, end=2020)
om2 <- window(om, start=2021)
om3 <- append(om1, om2, after=2020)
# om3 spans the full year range of om1 + om2
Original prompt

Summary

Add an append method for class FLombf that concatenates two FLombf objects along the year dimension: the first object up to (and including) a given after year, and the second object from the following year onwards.

Details

The method signature should follow the standard R append pattern:

append(x, values, after=dims(x)$maxyear)

where:

  • x is the first FLombf object
  • values is the second FLombf object
  • after is the year up to which x is used (default: last year of x); values is taken from after + 1 onwards

Implementation

Add the following to R/FLombf-class.R (after the combine section, around line 865):

# 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)
  }
) # }}}

Where to add it

Insert the new # append {{{ section after the existing # combine {{{ block (which ends around line 864 in R/FLombf-class.R) and before the # deviances {{{ block.

Export

Add "append" to the exportMethods() list in NAMESPACE (it is likely already exported via FLCore, but confirm it is listed or add it if missing).

Also add a short entry to NEWS.md under a new patch version:

## NEW FEATURES

- `append(FLombf, FLombf, after)` method to join two operating models at a year boundary.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: In flr/mse i need a function to append two objects of class FLombf, rthe first up to some year and the second from the next year

Assistant: Now I have a thorough understanding of the FLombf class. I'll create a append method that takes two FLombf objects and a year argument, taking the first object up to that year and the second from the next year. Looking at the existing window method and combine-based patterns in the code:

Assistant: I'm waiting for your confirmation to proceed with creating the pull request that adds the append method for FLombf.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Add append method to FLombf class for year dimension concatenation Add append method for FLombf to join two OMs at a year boundary Jun 4, 2026
Copilot AI requested a review from iagomosqueira June 4, 2026 13:01
@iagomosqueira iagomosqueira marked this pull request as ready for review June 4, 2026 13:12
@iagomosqueira iagomosqueira removed their request for review June 4, 2026 13:14

@iagomosqueira iagomosqueira left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default after should be the first year (minyear) of values.

Copilot AI requested a review from iagomosqueira June 4, 2026 13:16
@iagomosqueira iagomosqueira changed the base branch from main to devel June 4, 2026 13:17
@iagomosqueira iagomosqueira merged commit 2b4b01f into devel Jun 4, 2026
2 checks passed
@iagomosqueira iagomosqueira deleted the copilot/add-append-method-to-flombf branch June 4, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants