Skip to content

Commit

Permalink
add methods to top functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MOshima-PIFSC committed Dec 11, 2024
1 parent ab33670 commit 9a426d0
Showing 1 changed file with 115 additions and 22 deletions.
137 changes: 115 additions & 22 deletions R/fimsframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,81 +41,163 @@ setClass(
# is it problematic to set the generic for data? not sure...
# but it will not work without set generic
# can't call this data because there is already a generic

#' Get the data to be used in the model
#'
#' @param x A FIMSFrame object containing all the data used in
#' the model.
#' @return
#' A dataframe of all data in the model.
#' @rdname get_data
setGeneric("get_data", function(x) standardGeneric("get_data"))
#' @rdname get_data
setMethod("get_data", "FIMSFrame", function(x) x@data)
#' @rdname get_data
setMethod(
"get_data",
"data.frame",
function(x) FIMSFrame(x)@data
)

# example: so we can call fleets(obj) instead of obj@fleets
#' Get the fleets to be used in the model
#'
#' @param x A FIMSFrame object containing fleets in the model.
#' @return
#' A vector of all fleets in the model.
#' @rdname fleets
setGeneric("fleets", function(x) standardGeneric("fleets"))
#' @rdname fleets
setMethod("fleets", "FIMSFrame", function(x) x@fleets)
#' @rdname fleets
setMethod(
"fleets",
"data.frame",
function(x) FIMSFrame(x)@fleets
)

#' Get the number of years to be used in the model
#'
#' @param x A FIMSFrame object containing the number of years.
#' @return
#' An integer value of the number of years in the model.
#' @rdname n_years
setGeneric("n_years", function(x) standardGeneric("n_years"))
#' @rdname n_years
setMethod("n_years", "FIMSFrame", function(x) x@n_years)
#' @rdname n_years
setMethod(
"n_years",
"data.frame",
function(x) FIMSFrame(x)@n_years
)

#' Get the first year used in the model
#'
#' @param x A FIMSFrame object containing the first year of the model.
#' @return
#' An integer value of the first year in the model.
#' @rdname start_year
setGeneric("start_year", function(x) standardGeneric("start_year"))
#' @rdname start_year
setMethod("start_year", "FIMSFrame", function(x) x@start_year)
#' @rdname start_year
setMethod(
"start_year",
"data.frame",
function(x) FIMSFrame(x)@start_year
)

#' Get the last year used in the model
#'
#' @param x A FIMSFrame object containing the last year of the model.
#' @return
#' An integer value of the last year in the model.
#' @rdname end_year
setGeneric("end_year", function(x) standardGeneric("end_year"))
#' @rdname end_year
setMethod("end_year", "FIMSFrame", function(x) x@end_year)
#' @rdname end_year
setMethod(
"end_year",
"data.frame",
function(x) FIMSFrame(x)@end_year
)

#' Get the ages used in the model
#'
#' @param x A FIMSFrame object containing the ages in the model.
#' @return
#' A vector of the ages in the model.
#' @rdname ages
setGeneric("ages", function(x) standardGeneric("ages"))
#' @rdname ages
setMethod("ages", "FIMSFrame", function(x) x@ages)
#' @rdname ages
setMethod(
"ages",
"data.frame",
function(x) FIMSFrame(x)@ages
)

#' Get the number of ages used in the model
#'
#' @param x A FIMSFrame object containing the ages in the model.
#' @return
#' An integer value of the number of ages in the model.
#' @rdname n_ages
setGeneric("n_ages", function(x) standardGeneric("n_ages"))
#' @rdname n_ages
setMethod("n_ages", "FIMSFrame", function(x) x@n_ages)
#' @rdname n_ages
setMethod(
"n_ages",
"data.frame",
function(x) FIMSFrame(x)@n_ages
)

#' Get the lengths used in the model
#'
#' @param x A FIMSFrame object containing the lengths in the model.
#' @return
#' A vector of the lengths in the model.
#' @rdname get_lengths
setGeneric("get_lengths", function(x) standardGeneric("get_lengths"))
#' @rdname get_lengths
setMethod("get_lengths", "FIMSFrame", function(x) x@lengths)
#' @rdname get_lengths
setMethod(
"get_lengths",
"data.frame",
function(x) FIMSFrame(x)@lengths
)

#' Get the number of lengths used in the model
#'
#' @param x A FIMSFrame object containing the lengths in the model.
#' @return
#' An integer value of the number of lengths in the model.
#' @rdname n_lengths
setGeneric("n_lengths", function(x) standardGeneric("n_lengths"))
#' @rdname n_lengths
setMethod("n_lengths", "FIMSFrame", function(x) x@n_lengths)
#' @rdname n_lengths
setMethod(
"n_lengths",
"data.frame",
function(x) FIMSFrame(x)@n_lengths
)

#' Get the weight at age data used in the model
#'
#' @param x A FIMSFrame object containing the weight at age data
#' in the model.
#' @return
#' A dataframe of weight at age data used in the model.
#' @rdname weight_at_age
setGeneric("weight_at_age", function(x) standardGeneric("weight_at_age"))
#' @rdname weight_at_age
setMethod("weight_at_age", "FIMSFrame", function(x) x@weight_at_age)
#' @rdname weight_at_age
setMethod(
"weight_at_age",
"data.frame",
Expand All @@ -128,7 +210,11 @@ setMethod(

#' Get the weight at age data to be used in the model
#'
#' @param x The object containing weight at age data.
#' @param x A FIMSFrame object containing weight at age data.
#' @return
#' A vector of weight at age data. The order of the vector is the order
#' the data frame was in before this function was called because it is just
#' extracting a column.
#' @export
#' @rdname m_weight_at_age
setGeneric("m_weight_at_age", function(x) standardGeneric("m_weight_at_age"))
Expand All @@ -155,14 +241,16 @@ setMethod("m_ages", "FIMSFrame", function(x) {

#' Get the landings data to be used in the model
#'
#' @param x The object containing landings.
#' @param x A FIMSFrame object containing landings.
#' @return
#' A vector of landings data. The order of the vector is the order
#' the data frame was in before this function was called because it is just
#' extracting a column.
#' @export
#' @rdname m_landings
setGeneric("m_landings", function(x) standardGeneric("m_landings"))

#' Get the landings data to be used in the model
#'
#' @param x The FIMSFrame object containing landings.
#' @export
#' @rdname m_landings
setMethod(
"m_landings", "FIMSFrame",
function(x) {
Expand All @@ -176,16 +264,19 @@ setMethod(

#' Get the index data to be used in the model
#'
#' @param x The object containing index.
#' @param fleet_name The name of the fleet for the index data.
#' @param x A FIMSFrame object containing index data.
#' @param fleet_name A string providing the name of the fleet for which you
#' want the index data. Technically, you can pass it a
#' vector of strings but it is more common to pass it a single string.
#' @return
#' A vector of index data. The order of the vector is the order
#' the data frame was in before this function was called because it is just
#' extracting a column.
#' @export
#' @rdname m_index
setGeneric("m_index", function(x, fleet_name) standardGeneric("m_index"))

#' Get the index data to be used in the model
#'
#' @param x The FIMSFrame object containing index.
#' @param fleet_name The name of the fleet for the index data.
#' @export
#' @rdname m_index
setMethod(
"m_index", "FIMSFrame",
function(x, fleet_name) {
Expand All @@ -201,17 +292,19 @@ setMethod(

#' Get the age-composition data to be used in the model
#'
#' @param x The object containing the age-composition data.
#' @param fleet_name The name of the fleet for the age-composition data.
#' @param x A FIMSFrame object containing age-composition data.
#' @param fleet_name A string providing the name of the fleet for which you
#' want the age-composition data. Technically, you can pass it a
#' vector of strings but it is more common to pass it a single string.
#' @return
#' A vector of age-composition data. The order of the vector is the order
#' the data frame was in before this function was called because it is just
#' extracting a column.
#' @export
#' @rdname m_agecomp
setGeneric("m_agecomp", function(x, fleet_name) standardGeneric("m_agecomp"))
# Should we add name as an argument here?

#' Get the age-composition data data to be used in the model
#'
#' @param x The FIMSFrame containing age-composition data.
#' @param fleet_name The name of the fleet for the age-composition data.
#' @export
#' @rdname m_agecomp
setMethod(
"m_agecomp", "FIMSFrame",
function(x, fleet_name) {
Expand Down

0 comments on commit 9a426d0

Please sign in to comment.