Issue
The function compute.catch.biomass() is created twice; both instances produce the same outputs but take different inputs. In plotting/compute_plot_products.R the function takes a file path as input...
|
compute.catch.biomass <- function(model.dir, nyr, years){ |
|
|
|
data <- read.data.files(model.dir) |
|
|
|
weight.at.age <- data$waa[1:nyr,] |
|
|
|
fb.nya <- data$foodbait_catch[1:nyr,] |
|
pound.nya <- data$pound_catch[1:nyr,] |
|
gillnet.nya <- data$gillnet_catch[1:nyr,] |
|
seine.yield <- data$seine_yield[1:nyr] |
|
|
|
fb.nya.biomass <- weight.at.age * fb.nya |
|
pound.nya.biomass <- weight.at.age * pound.nya |
|
gillnet.nya.biomass <- weight.at.age * gillnet.nya |
|
|
|
fb.biomass.annual <- rowSums(fb.nya.biomass) # Now sum the biomass over all age classes for each year |
|
pound.biomass.annual <- rowSums(pound.nya.biomass) |
|
gillnet.biomass.annual <- rowSums(gillnet.nya.biomass) |
|
|
|
fb.biomass.annual <- replace(fb.biomass.annual, fb.biomass.annual == 0, NA) |
|
pound.biomass.annual <- replace(pound.biomass.annual, pound.biomass.annual == 0, NA) |
|
gillnet.biomass.annual <- replace(gillnet.biomass.annual, gillnet.biomass.annual == 0, NA) |
|
seine.yield <- replace(seine.yield, seine.yield == 0, NA) |
|
|
|
# Matrix of catches by gear type in mt |
|
total.catch <- cbind(fb.biomass.annual, pound.biomass.annual, gillnet.biomass.annual, seine.yield) |
|
total.catch[is.na(total.catch)] <- 0 |
|
total.catch.biomass <- rowSums(total.catch) # total catches by year in mt |
|
|
|
return(total.catch.biomass) |
|
|
|
} |
...whereas the compute.catch.biomass() created in functions/fun_read_dat.R takes a data object.
|
compute.catch.biomass <- function(data, nyr){ |
|
|
|
weight.at.age <- data$waa[1:nyr,] |
|
|
|
fb.nya <- data$foodbait_catch[1:nyr,] |
|
pound.nya <- data$pound_catch[1:nyr,] |
|
gillnet.nya <- data$gillnet_catch[1:nyr,] |
|
seine.yield <- data$seine_yield[1:nyr] |
|
|
|
fb.nya.biomass <- weight.at.age * fb.nya |
|
pound.nya.biomass <- weight.at.age * pound.nya |
|
gillnet.nya.biomass <- weight.at.age * gillnet.nya |
|
|
|
fb.biomass.annual <- rowSums(fb.nya.biomass) # Now sum the biomass over all age classes for each year |
|
pound.biomass.annual <- rowSums(pound.nya.biomass) |
|
gillnet.biomass.annual <- rowSums(gillnet.nya.biomass) |
|
|
|
fb.biomass.annual <- replace(fb.biomass.annual, fb.biomass.annual == 0, NA) |
|
pound.biomass.annual <- replace(pound.biomass.annual, pound.biomass.annual == 0, NA) |
|
gillnet.biomass.annual <- replace(gillnet.biomass.annual, gillnet.biomass.annual == 0, NA) |
|
seine.yield <- replace(seine.yield, seine.yield == 0, NA) |
|
|
|
# Matrix of catches by gear type in mt |
|
total.catch <- cbind(fb.biomass.annual, pound.biomass.annual, gillnet.biomass.annual, seine.yield) |
|
total.catch[is.na(total.catch)] <- 0 |
|
total.catch.biomass <- rowSums(total.catch) # total catches by year in mt |
|
|
|
return(total.catch.biomass) |
|
|
|
} |
This throws in error when executing plotting/plot_management_outputs.R because the former script is sourced in line 4 but then supplies a data object to the function in line 52.
|
source(file=paste0(here::here("plotting/", "compute_plot_products.R"))) |
|
raw.data <- read.data.files(model.dir) |
|
total.catch.biomass <- compute.catch.biomass(raw.data$PWS_ASA.dat, nyr) %>% round(., 2) |
Also note that plotting/compute_plot_products.R sources functions/fun_read_dat.R in line 3.
Solution
Resolve namespace clash. I commented out lines 61-92 in plotting/compute_plot_products.R to accommodate the use case in plotting/plot_management_outputs.R.
Issue
The function
compute.catch.biomass()is created twice; both instances produce the same outputs but take different inputs. Inplotting/compute_plot_products.Rthe function takes a file path as input...pws-herring-basa/plotting/compute_plot_products.R
Lines 61 to 92 in caef7da
...whereas the
compute.catch.biomass()created infunctions/fun_read_dat.Rtakes a data object.pws-herring-basa/functions/fun_read_dat.R
Lines 133 to 162 in caef7da
This throws in error when executing
plotting/plot_management_outputs.Rbecause the former script is sourced in line 4 but then supplies a data object to the function in line 52.pws-herring-basa/plotting/plot_management_outputs.R
Line 4 in caef7da
pws-herring-basa/plotting/plot_management_outputs.R
Lines 51 to 52 in caef7da
Also note that
plotting/compute_plot_products.Rsourcesfunctions/fun_read_dat.Rin line 3.Solution
Resolve namespace clash. I commented out lines 61-92 in
plotting/compute_plot_products.Rto accommodate the use case inplotting/plot_management_outputs.R.