Skip to content

Commit

Permalink
Merge pull request #364 from StoXProject/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
arnejohannesholmin authored Sep 18, 2024
2 parents 880987c + e7f91ce commit f359f8c
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ jobs:
# - {os: macOS-latest, r: '3.6', pkgext: '.tgz'} # Not used in RstoxFramework
- {os: windows-latest, r: 'release', pkgext: '.zip'}
- {os: windows-latest, r: '4.3', pkgext: '.zip'}
- {os: windows-latest, r: '4.2', pkgext: '.zip'} # Temporarily disabling this due to new sf release not ready for R 4.2
# - {os: windows-latest, r: '4.2', pkgext: '.zip'} # Removed due to sf failing to build
# - {os: windows-latest, r: '4.1', pkgext: '.zip'} # Disabled due to stringi failure
#- {os: windows-latest, r: '4.0', pkgext: '.zip', rspm: "https://cloud.r-project.org"} # Too slow
#- {os: windows-latest, r: '3.6', pkgext: '.zip', rspm: "https://cloud.r-project.org"} # Too slow
- {os: ubuntu-latest, r: 'release', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-22.04, r: '4.3', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-22.04, r: '4.2', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: '4.1', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: '4.0', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"}
# - {os: ubuntu-20.04, r: '4.1', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"} # Removed due to sf failing to build
# - {os: ubuntu-20.04, r: '4.0', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"} # Removed due to sf failing to build
#- {os: ubuntu-20.04, r: '3.6', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"}

env:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: RstoxBase
Version: 2.0.1-9001
Date: 2024-09-02
Version: 2.0.1-9002
Date: 2024-09-17
Title: Base StoX Functions
Authors@R: c(
person(given = "Arne Johannes",
Expand Down
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# RstoxData v2.0.1-9002 (2024-09-17)
* Renamed ReportVariable to TargetVariable and ReportVariableUnit to TargetVariableUnit in ReportSpeciesCategoryCatch() for consistency with other report functions.
* Added TargetVariable and TargetVariableUnit in ReportPreySpeciesCategoryCatch().


# RstoxData v2.0.1-9001 (2024-09-01)
* Added functions PreySpeciesCategoryCatch and ReportPreySpeciesCategoryCatch.
* Added the ReportFunction "number", "fractionOfOccurrence" and "fractionOfSum".
Expand Down Expand Up @@ -36,7 +41,7 @@
* Added documentation of ReportFunctions.
* Added the exported getFunctionArgumentHierarchyForSpcificationParameters() used in stoxFunctionAttributes.
* Fixed report functions number(), fractionOfOccurrence() and fractionOfSum().
* Fixed bug where IndividualAge was not avaiable as TargetVariable in reports (due to class integer, which was not accounted for).
* Fixed bug where IndividualAge was not available as TargetVariable in reports (due to class integer, which was not accounted for).


# RstoxBase v1.11.4-9007 (2024-04-19)
Expand Down Expand Up @@ -167,7 +172,7 @@


# RstoxBase v1.10.3 (2022-11-21)
* Added the parameter TargetVariableUnit in ReportSuperIndividuals() and ReportQuantity(), DensityUnit in ReportDensity(), and ReportVariableUnit in ReportSpeciesCategoryCatch(), which all acn be used to set the units for the report.
* Added the parameter TargetVariableUnit in ReportSuperIndividuals() and ReportQuantity(), DensityUnit in ReportDensity(), and ReportVariableUnit in ReportSpeciesCategoryCatch(), which all can be used to set the units for the report.


# RstoxBase v1.10.2 (2022-10-31)
Expand Down
40 changes: 21 additions & 19 deletions R/Report.R
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ getReportFunctionElementByFunctionName <- function(x, element) {
#' Reports the sum, mean or other functions on a variable of the \code{\link{SpeciesCategoryCatch}}.
#'
#' @inheritParams ModelData
#' @param ReportVariable The column to report.
#' @param ReportVariableUnit The unit to use for the \code{ReportVariable}. See RstoxData::StoxUnits for possible units (look for the appropriate quantity, e.g. "length" for IndividualTotalLength, and use the shortname in the \code{ReportVariableUnit}).
#' @param TargetVariable The column to report.
#' @param TargetVariableUnit The unit to use for the \code{TargetVariable}. See RstoxData::StoxUnits for possible units (look for the appropriate quantity, e.g. "length" for IndividualTotalLength, and use the shortname in the \code{TargetVariableUnit}).
#'
#' @details This function is useful to, e.g, sum Biomass for each SpeciesCategory and IndividualTotalLenght, or average IndividualTotalLength for each IndiivdualAge and Stratum.
#'
Expand All @@ -655,12 +655,12 @@ getReportFunctionElementByFunctionName <- function(x, element) {
#'
ReportSpeciesCategoryCatch <- function(
SpeciesCategoryCatchData,
ReportVariable = c("TotalCatchNumber", "TotalCatchWeight"),
ReportVariableUnit = character()
TargetVariable = c("TotalCatchWeight", "TotalCatchNumber"),
TargetVariableUnit = character()
){

# Get the ReportVariable:
ReportVariable <- RstoxData::match_arg_informative(ReportVariable)
# Get the TargetVariable:
TargetVariable <- RstoxData::match_arg_informative(TargetVariable)

# Warning if there are species categories which are empty string:
categoryVariable <- getDataTypeDefinition(dataType = "DensityData", elements = "categoryVariable", unlist = TRUE)
Expand All @@ -669,18 +669,18 @@ ReportSpeciesCategoryCatch <- function(
warning("StoX: There are empty strings for the ", categoryVariable, ". These will be included in the column V1 in the SpeciesCategoryCatch table.")
}

SpeciesCategoryCatchData[[ReportVariable]] <- setUnitRstoxBase(
SpeciesCategoryCatchData[[ReportVariable]],
SpeciesCategoryCatchData[[TargetVariable]] <- setUnitRstoxBase(
SpeciesCategoryCatchData[[TargetVariable]],
dataType = "SpeciesCategoryCatchData",
variableName = ReportVariable,
unit = ReportVariableUnit
variableName = TargetVariable,
unit = TargetVariableUnit
)

# Create the table with species categories in the columns:
ReportSpeciesCategoryCatchData <- data.table::dcast(
SpeciesCategoryCatchData,
formula = Haul ~ get(categoryVariable),
value.var = ReportVariable,
value.var = TargetVariable,
fun.aggregate = sum
)

Expand All @@ -699,8 +699,8 @@ ReportSpeciesCategoryCatch <- function(
by = "Haul"
)

if(RstoxData::hasUnit(SpeciesCategoryCatchData[[ReportVariable]], property = "shortname")) {
unit <- RstoxData::getUnit(SpeciesCategoryCatchData[[ReportVariable]], property = "shortname")
if(RstoxData::hasUnit(SpeciesCategoryCatchData[[TargetVariable]], property = "shortname")) {
unit <- RstoxData::getUnit(SpeciesCategoryCatchData[[TargetVariable]], property = "shortname")
ReportSpeciesCategoryCatchData <- cbind(ReportSpeciesCategoryCatchData, Unit = unit)
}

Expand Down Expand Up @@ -817,7 +817,6 @@ filterTable <- function(table, filter = character()) {
#'
#' @inheritParams ModelData
#' @inheritParams general_report_arguments
#' @param TotalPreyCatchWeightUnit The unit to use for the \code{TotalPreyCatchWeight}. Run the following in R for possible units: subset(RstoxData::StoxUnits, quantity == "mass", select = "shortname").
#'
#' @return
#' A \code{\link{ReportPreySpeciesCategoryCatchData}} object.
Expand All @@ -826,8 +825,10 @@ filterTable <- function(table, filter = character()) {
#'
ReportPreySpeciesCategoryCatch <- function(
PreySpeciesCategoryCatchData,
TotalPreyCatchWeightUnit = character(),
#TargetVariable = character(),
# No longer hard coding this to weight:
#TotalPreyCatchWeightUnit = character(),
TargetVariable = c("TotalPreyCatchWeight", "TotalPreyCatchNumber"),
TargetVariableUnit = character(),
ReportFunction = getReportFunctions(use = "Baseline"),
GroupingVariables = character(),
InformationVariables = character(),
Expand All @@ -839,8 +840,9 @@ ReportPreySpeciesCategoryCatch <- function(
FractionOverVariable = character()
)
{
# Only Density is relevant here:
TargetVariable <- "TotalPreyCatchWeight"
# No longer hard coding this to weight:
## Only Density is relevant here:
#TargetVariable <- "TotalPreyCatchWeight"

# Issue a warning if RemoveMissingValues = TRUE:
if(isTRUE(RemoveMissingValues) && any(is.na(PreySpeciesCategoryCatchData[[TargetVariable]]))) {
Expand All @@ -851,7 +853,7 @@ ReportPreySpeciesCategoryCatch <- function(
PreySpeciesCategoryCatchData[[TargetVariable]],
dataType = "PreySpeciesCategoryCatchData",
variableName = TargetVariable,
unit = TotalPreyCatchWeightUnit
unit = TargetVariableUnit
)

output <- aggregateBaselineDataOneTable(
Expand Down
2 changes: 1 addition & 1 deletion R/Spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ polygonArea_accurate <- function(stratumPolygon, useLonLatCentroid = TRUE) {
# Re-project for equal area projection, using the centroid of the multipolygon:

# rgeos is retiring, so we use sf instead to get the centroid:
centroid <- getCentroid(stratumPolygon, iterativeCentroidCalculation = !useLonLatCentroid)
centroid <- getCentroid(stratumPolygon, iterativeCentroidCalculation = !useLonLatCentroid)

#centroid <- rgeos::gCentroid(stratumPolygon)@coords
laea.CRS <- paste0(
Expand Down
28 changes: 28 additions & 0 deletions R/backwardCompatibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ backwardCompatibility_RstoxBase <- list(
functionName = "ReportQuantity",
modelName = "report",
parameterName = "FractionOverVariable"
),
list(
changeVersion = "2.0.1-9002",
functionName = "ReportPreySpeciesCategoryCatch",
modelName = "report",
parameterName = "TargetVariable",
parameterValue = "TotalPreyCatchWeight"
)
),

Expand Down Expand Up @@ -416,6 +423,27 @@ backwardCompatibility_RstoxBase <- list(
modelName = "baseline",
parameterName = "AbundanceData",
newParameterName = "QuantityData"
),
list(
changeVersion = "2.0.1-9002",
functionName = "ReportSpeciesCategoryCatch",
modelName = "report",
parameterName = "ReportVariable",
newParameterName = "TargetVariable"
),
list(
changeVersion = "2.0.1-9002",
functionName = "ReportSpeciesCategoryCatch",
modelName = "report",
parameterName = "ReportVariableUnit",
newParameterName = "TargetVariableUnit"
),
list(
changeVersion = "2.0.1-9002",
functionName = "ReportPreySpeciesCategoryCatch",
modelName = "report",
parameterName = "TotalPreyCatchWeightUnit",
newParameterName = "TargetVariableUnit"
)
),

Expand Down
40 changes: 34 additions & 6 deletions R/stoxFunctionAttributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,13 @@ stoxFunctionAttributes <- list(
getFunctionArgumentHierarchyForSpcificationParameters(
use = "Baseline",
functionName = "ReportFunction"
),
list(
TargetVariableUnit = list(
ReportFunction = function(functionArguments) {
!startsWith(functionArguments$ReportFunction, "fractionOf")
}
)
)
)
),
Expand All @@ -1369,6 +1376,13 @@ stoxFunctionAttributes <- list(
getFunctionArgumentHierarchyForSpcificationParameters(
use = "Baseline",
functionName = "ReportFunction"
),
list(
TargetVariableUnit = list(
ReportFunction = function(functionArguments) {
!startsWith(functionArguments$ReportFunction, "fractionOf")
}
)
)
)
),
Expand All @@ -1395,6 +1409,13 @@ stoxFunctionAttributes <- list(
getFunctionArgumentHierarchyForSpcificationParameters(
use = "Baseline",
functionName = "ReportFunction"
),
list(
DensityUnit = list(
ReportFunction = function(functionArguments) {
!startsWith(functionArguments$ReportFunction, "fractionOf")
}
)
)
)
),
Expand All @@ -1408,7 +1429,7 @@ stoxFunctionAttributes <- list(
functionCategory = "report",
functionOutputDataType = "ReportSpeciesCategoryCatchData",
functionParameterFormat = list(
ReportVariableUnit = "reportVariableUnit_ReportSpeciesCategoryCatch"
TargetVariableUnit = "targetVariableUnit_ReportSpeciesCategoryCatch"
)
),

Expand All @@ -1431,6 +1452,13 @@ stoxFunctionAttributes <- list(
getFunctionArgumentHierarchyForSpcificationParameters(
use = "Baseline",
functionName = "ReportFunction"
),
list(
TargetVariableUnit = list(
ReportFunction = function(functionArguments) {
!startsWith(functionArguments$ReportFunction, "fractionOf")
}
)
)
)
),
Expand Down Expand Up @@ -2344,14 +2372,14 @@ processPropertyFormats <- list(



reportVariableUnit_ReportSpeciesCategoryCatch = list(
targetVariableUnit_ReportSpeciesCategoryCatch = list(
class = "single",
title = "Select unit for the ReportVariable",
possibleValues = function(ReportVariable) {
title = "Select unit for the TargetVariable",
possibleValues = function(TargetVariable) {
dataType <- "SpeciesCategoryCatchData"
quantity <- getBaseUnit(dataType = dataType, variableName = ReportVariable, element = "quantity")
quantity <- getBaseUnit(dataType = dataType, variableName = TargetVariable, element = "quantity")
if(!length(quantity) || is.na(quantity)) {
warning("StoX: No units defined for the variable ", ReportVariable, " of datatype ", dataType)
warning("StoX: No units defined for the variable ", TargetVariable, " of datatype ", dataType)
list()
}
else {
Expand Down
Binary file modified inst/extdata/functionArguments.rds
Binary file not shown.
7 changes: 5 additions & 2 deletions man/ReportPreySpeciesCategoryCatch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/ReportSpeciesCategoryCatch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f359f8c

Please sign in to comment.