Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: RstoxData
Version: 2.2.0-9011
Date: 2026-01-19
Date: 2026-01-23
Title: Tools to Read and Manipulate Fisheries Data
Authors@R: c(
person(given = "Arne Johannes",
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# RstoxData v2.2.0-9011 (2026-01-11)
# RstoxData v2.2.0-9011 (2026-01-23)
* Fixed bug in TranslateICESDatsusc(), where conditional values were ignored.
* Changed NA to empty string ("") in WriteICESDatsusc().
* Changed Weight in ICESDatsusc() to always be grouped (changed in the column Notes).
* Fixed bug in ICESAcoustic, where reading an NMDEchosounder file in the ReadAcoustic process used as input failed in the merging of tables "distance", "frequency", "sa", Now expanded to merge "distance", "frequency", "ch_type", "sa_by_acocat" and "sa".
* Added units for area_weight_density.

Expand Down
51 changes: 49 additions & 2 deletions R/Definitions.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,57 @@ initiateRstoxData <- function(){
"LengthClass",
"FishID"
)
),
# ICESDatsusc keys:
ICESDatsusc = list(
FI = character(),
HH = c(
"Ship",
"Gear",
"HaulNo",
"StationNumber",
"Year",
"Month",
"Day",
"Time"
),
PI = c(
"Ship",
"Gear",
"HaulNo",
"StationNumber",
"Year",
"Month",
"Day",
"Time",
"FishID",
"AphiaIDPredator"
),
PP = c(
"Ship",
"Gear",
"HaulNo",
"StationNumber",
"Year",
"Month",
"Day",
"Time",
"FishID",
"AphiaIDPredator",
"AphiaIDPrey",
"IdentMet",
"DigestionStage",
"GravMethod",
"SubFactor",
"PreySequence"
)
)
)
# Add the ICESDatsusc keys as the same as the ICESDatras:
keys$ICESDatsusc <- keys$ICESDatras








Expand Down
22 changes: 10 additions & 12 deletions R/StoxExport.R
Original file line number Diff line number Diff line change
Expand Up @@ -1938,10 +1938,11 @@ ICESDatsuscOne <- function(
AphiaIDPredator,AphiaIDPrey,IdentMet,DigestionStage,GravMethod,
SubFactor,PreySequence)]

# Set the weight to computed weight if possible:
# Set the weight to grouped weight:
hasCountAndTotalCount <- !is.na(finalPP$TotalCount)
finalPP[hasCountAndTotalCount, Notes := 'Computed using: total weight * count in length group / count for all length group']
finalPP[hasCountAndTotalCount, Weight := Weight * Count / TotalCount]
finalPP[, Notes := 'Grouped weight']
# Removed:
# finalPP[hasCountAndTotalCount, Weight := Weight * Count / TotalCount]

#Handling number of unique species in prey sampled in each individual fish
#TODO: Needs to be checked
Expand Down Expand Up @@ -2002,23 +2003,21 @@ WriteICESDatsusc <- function(ICESDatsuscData){
# na = "-9"
#)

WriteICESDatsuscData <- WriteICESDatsuscOne(ICESDatsuscData)
WriteICESDatsuscData <- WriteICESDatsuscOne(ICESDatsuscData, na = "")

return(WriteICESDatsuscData)
}


WriteICESDatsuscOne <- function(ICESDatsuscData){
WriteICESDatsuscOne <- function(ICESDatsuscData, na = ""){

# Convert all tables to string matrix with header and record, and rbind:
ICESDatsuscCSVDataOne<- convertToRecordTypeMatrix(ICESDatsuscData)
### # Replace NAs:
### if(length(na)) {
### ICESDatsuscCSVDataOne <- lapply(ICESDatsuscCSVDataOne, function(x) {x[is.na(x)] <- na; x})
### }

# IMPORTANT NOTE: The ICES DATRAS format assumes that the three tables HH, HL and CA are stacked in a comma separated file but without padding the tables to equal number of columns as is done for ICESAcoustic and ICESBiotic. For this reason we need to paste the data to a chatacter vector and write as lines. RstoxFramework detects that the output as a vector of characters and uses writeLines() to produce the file.

# Replace NAs:
if(length(na)) {
ICESDatsuscCSVDataOne <- lapply(ICESDatsuscCSVDataOne, function(x) {x[is.na(x)] <- na; x})
}

# Convert each line of each table to comma separated:
ICESDatsuscCSVDataOne <- lapply(ICESDatsuscCSVDataOne, apply, 1, paste, collapse = ",")
Expand All @@ -2031,4 +2030,3 @@ WriteICESDatsuscOne <- function(ICESDatsuscData){




Loading