Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sto xv4.1.0 #393

Merged
merged 2 commits into from
Oct 30, 2024
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
30 changes: 15 additions & 15 deletions .github/workflows/check-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ jobs:
config:
# Latest macOS will use the big-sur-arm64 folder when deploying to the drat repo:
- {os: macOS-latest, r: 'release', pkgext: '.tgz'}
- {os: macOS-latest, r: '4.3', pkgext: '.tgz'}
- {os: macOS-latest, r: 'oldrel', pkgext: '.tgz'}

# macOS-13 will use the big-sur-x86_64 folder when deploying to the drat repo:
- {os: macOS-13, r: 'release', pkgext: '.tgz'}
- {os: macOS-13, r: '4.3', pkgext: '.tgz'}
- {os: macOS-13, r: 'oldrel', pkgext: '.tgz'}

- {os: windows-latest, r: 'release', pkgext: '.zip'}
- {os: windows-latest, r: '4.3', pkgext: '.zip'}
- {os: windows-latest, r: 'oldrel', pkgext: '.zip'}

- {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-22.04, r: 'oldrel', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-22.04, r: 'oldrel-1', pkgext: '.tar.gz', rspm: "https://cloud.r-project.org"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand All @@ -50,7 +50,7 @@ jobs:
#### 1. Setup: ####
###################

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Prepare for deployment at push
if: github.event_name == 'push'
Expand Down Expand Up @@ -214,7 +214,7 @@ jobs:
system(paste0("PKG_FREL=", Sys.getenv("PKG_FILE"), " >> ", Sys.getenv("GITHUB_ENV")))
shell: Rscript {0}

- name: Build package binary archive from branches develop, testing and master for Windows and macOS (this builds also on matrix.config.r = release, which can or can not be a duplicate)
- name: Build package binary archive from branches develop, testing and master for Windows and macOS
if: (runner.os == 'Windows' || runner.os == 'macOS') && github.event_name == 'push' && (github.ref_name == 'master' || github.ref_name == 'testing' || github.ref_name == 'develop')
run: |
pkgbuild::build(".", dest_path = ".", binary = TRUE)
Expand All @@ -231,29 +231,29 @@ jobs:
#### 5. Deploy to the drat repos: ####
######################################

## 5a. Upload to the official (DRAT) repo, but only from the master branch. Here we skip the matrix.config.r = release, as a new StoX release should be ready shortly after each R minor release and listed specifically in the matrix.config:
## 5a. Upload to the official (DRAT) repo, but only from the master branch:
- name: Upload to the official (DRAT) repo
if: ( (runner.os == 'Windows' && matrix.config.r != 'release') || (runner.os == 'macOS' && matrix.config.r != 'release') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'master'
if: ( (runner.os == 'Windows') || (runner.os == 'macOS') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'master'
env:
BUILD_NUMBER: ${{ github.sha }}
DRAT_DEPLOY_TOKEN: ${{ secrets.DRAT_DEPLOY_TOKEN }}
run: . repo_deploy.sh
shell: bash


## 5b. Upload to the (DRAT) testingRepo, but only from the testing branch. Here we skip the matrix.config.r = release, as a new StoX release should be ready shortly after each R minor release and listed specifically in the matrix.config:
## 5b. Upload to the (DRAT) testingRepo, but only from the testing branch:
- name: Upload to the testing (DRAT) repo
if: ( (runner.os == 'Windows' && matrix.config.r != 'release') || (runner.os == 'macOS' && matrix.config.r != 'release') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'testing'
if: ( (runner.os == 'Windows') || (runner.os == 'macOS') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'testing'
env:
BUILD_NUMBER: ${{ github.sha }}
DRAT_DEPLOY_TOKEN: ${{ secrets.DRAT_DEPLOY_TOKEN }}
run: . testingRepo_deploy.sh
shell: bash


## 5c. Upload to the (DRAT) unstableRepo, but only from the develop branch. Here we skip the matrix.config.r = release, as a new StoX release should be ready shortly after each R minor release and listed specifically in the matrix.config:
## 5c. Upload to the (DRAT) unstableRepo, but only from the develop branch:
- name: Upload to the unstable (DRAT) repo
if: ( (runner.os == 'Windows' && matrix.config.r != 'release') || (runner.os == 'macOS' && matrix.config.r != 'release') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'develop'
if: ( (runner.os == 'Windows') || (runner.os == 'macOS') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'develop'
env:
BUILD_NUMBER: ${{ github.sha }}
DRAT_DEPLOY_TOKEN: ${{ secrets.DRAT_DEPLOY_TOKEN }}
Expand All @@ -267,7 +267,7 @@ jobs:
###############################

- name: Create release on GitHub and upload files for testing branch
if: ( (runner.os == 'Windows' && matrix.config.r != 'release') || (runner.os == 'macOS' && matrix.config.r != 'release') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'testing'
if: ( (runner.os == 'Windows') || (runner.os == 'macOS') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'testing'
uses: ncipollo/release-action@v1
with:
allowUpdates: true
Expand All @@ -278,7 +278,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Create release on GitHub and upload files for master branch
if: ( (runner.os == 'Windows' && matrix.config.r != 'release') || (runner.os == 'macOS' && matrix.config.r != 'release') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'master'
if: ( (runner.os == 'Windows') || (runner.os == 'macOS') || (runner.os == 'Linux' && matrix.config.r == 'release') ) && github.event_name == 'push' && github.ref_name == 'master'
uses: ncipollo/release-action@v1
with:
allowUpdates: true
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: RstoxData
Version: 2.0.1-9005
Date: 2024-10-29
Version: 2.0.1-9006
Date: 2024-10-30
Title: Tools to Read and Manipulate Fisheries Data
Authors@R: c(
person(given = "Edvin",
Expand Down
10 changes: 8 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# RstoxData v2.0.1-9005 (2024-10-22)
# RstoxData v2.0.1-9006 (2024-10-30)
* Fixed warnings in translateOneTable() so that a warning is given if the variable to translate is not present in any table, and if any conditional variables are not present in a table to be translated.
* Applied 'release' and 'oldrel' in the check-full.yaml, securing that binaries are built for the current and previous R minor versjon.


# RstoxData v2.0.1-9005 (2024-10-28)
* Fixed bug in as.numeric_IfPossible() used by setorderv_numeric() and orderRowsByKeys() where individual elements could be set to NA in a vector unless all of the values were NA after conversion to numeric. In the new version all of the values must be convertible to numeric for a numeric vector to be returned. In addition setorderv_numeric() has gained the parameter split, which is used in RstoxBase::formatOutput() as split = c("-", "/") to split both by the within StoX key separator and the between StoX kye separator used in IDs such as Sample and Individual. This bugfix may result in different sorting of StoxBiotic, particularly for NMDBiotic data with herring coded as catchcategory 161722.G03, 161722.G05 or 161722.G07.
* Changed the drop down list of ConditionalVariableNames in Translate functions to only include the variables in the table of the VariableName (and also excluding the VariableName). Previously all variables of the entire data were listed, which was confusing since only those present in the relevant table could be used.
* Changed the behavior of Translate functions when a variable that is not present in the table is used as a conditional variable. Before this conditional variable was effectively ignored, but in the new version the behavior is to give a warning and not perform any translation.
* Added a warning if no values are translated in Translate functions.
* Added the new GeneticPopulationCode to ICESBiotic().
* Added the new GeneticPopulationCode to ICESBiotic().
* Temporarily hiding Prey tables in StoxBiotic().

# RstoxData v2.0.1-9004 (2024-10-08)
* Fixed a bug where certain values of BiologyLengthCode were shifted one integer value down in ICESBiotic(). The bug is related to floating point precision which causes some values to be slightly lower than the corresponding integer after calculations. In R one example is format(29 / 100 * 100, digits = 20) = "28.999999999999996447", which results in 28 when converted to integer. The following values are affected:
Expand Down
56 changes: 31 additions & 25 deletions R/DefineAndUpdateVariables.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,6 @@ translateVariables <- function(
translationList = translationList
))

#if(any(someButNotAllPresent)) {
# warning("StoX: The following tables contain some but not all of the variables of the Translation: ", paste0(names(data)[someButNotAllPresent], collapse = ", "))
#}

# Run the conversion for each table of the data:
lapplyToStoxData(
data,
Expand All @@ -295,6 +291,24 @@ translateVariables <- function(
# Function to translate one table:
translateOneTable <- function(table, translationList, translate.keys = FALSE, PreserveClass = TRUE, warnMissingTranslation = FALSE) {

# If the variable to translate is present in the table, check whether the conditional variables are present in the table:
variableToTranslate <- sapply(translationList, function(x) names(x)[1])
variableToTranslateIsPresent <- variableToTranslate %in% names(table)

# Abort if the variableToTranslate are not present in the table:
if(!any(variableToTranslateIsPresent)) {
# This return value is currently not used:
return(FALSE)
}

# List the conditional variables and check whether those linked to the variables present in the table are also present:
conditionalVariables <- sapply(translationList, function(x) names(x)[-c(1, 2)])
conditionalVariablesNotPresentInTable <- setdiff(unlist(conditionalVariables[variableToTranslateIsPresent]), names(table))
if(length(conditionalVariablesNotPresentInTable)) {
warning("StoX: The following conditional variables are not present in the table: ", paste(conditionalVariablesNotPresentInTable, collapse = ", "), ".")
}


# Apply the translation, one line at the time:
matches <- lapply(
translationList,
Expand All @@ -320,6 +334,17 @@ translateOneTable <- function(table, translationList, translate.keys = FALSE, Pr
if(length(matches[[ind]])) {
variableToTranslate <- names(translationList[[ind]])[1]
replacement <- translationList[[ind]]$NewValue

# Compare classes, and change class of the replacement of different to capture the warning but avoid data.table warning "Coercing --- RHS to --- to match the type of column..."
variableToTranslate_class <- class(table[[variableToTranslate]])
replacement_class <- class(replacement)

replacement_original <- replacement
suppressWarnings(class(replacement) <- variableToTranslate_class)
if(is.na(replacement) && !is.na(replacement_original)) {
warning("StoX: The class of the NewValue of the translation table (", replacement_class, ": ", replacement_original, ") does not match the class of the ", variableToTranslate, " (", variableToTranslate_class, "). Missing value (NA) introduced.")
}

table[matches[[ind]], eval(variableToTranslate) := ..replacement]
}
}
Expand Down Expand Up @@ -414,13 +439,7 @@ translateOneTranslationOneTable <- function(translationListOne, table, translate
table = table
)

### translationListOneConverted <- convertClassToExistingOneElement(
### list = translationListOne,
### x = table,
### element = "NewValue"
### )

# Check whether the NewValue has changed, and if it has changegd to NA, report a warning:
# Check whether the NewValue has changed, and if it has changed to NA, report a warning:
if(!identical(translationListOneConverted, translationListOne)) {

atNAAndDiffering <- is.na(translationListOne) & !is.na(translationListOneConverted)
Expand All @@ -433,7 +452,6 @@ translateOneTranslationOneTable <- function(translationListOne, table, translate
}



# Replace by the new value:
if(variableToTranslate %in% names(table)) {
varsToMatch <- setdiff(names(translationListOne), "NewValue")
Expand All @@ -442,24 +460,12 @@ translateOneTranslationOneTable <- function(translationListOne, table, translate
# Any empty matches indicate that the variable of interest is not present, and triggers a warning and no match:
emptyMatches <- lengths(matches) == 0
if(any(emptyMatches)) {
warning("StoX: The following variables are used in the translation but are not present in the table. This results in no translation: ", paste(varsToMatch[emptyMatches], collapse = ", "), ".")
#warning("StoX: The following variables are used in the translation but are not present in the table. This results in no translation: ", paste(varsToMatch[emptyMatches], collapse = ", "), ".")
matches[emptyMatches] <- rep(list(FALSE), sum(emptyMatches))
}

matches <- apply(do.call(cbind, matches), 1, all)

if(!any(matches)) {
warning("StoX: No values were translated. Did you spell the values of the variable to translate correctly?")
}

### # Change the type after matching and before translating to avoid type conversion warninigs:
### if(!PreserveClass) {
### setColumnClasses(table, structure(list(class(translationListOne$NewValue)), names = variableToTranslate))
### }
###
### # Replace:
### replacement <- translationListOne$NewValue
### table[matches, eval(variableToTranslate) := ..replacement]

return(matches)
}
Expand Down
2 changes: 1 addition & 1 deletion R/Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ createOrderKey <- function(x, split = "/") {
}

# Split by the 'split' argument:
if(!grepl(split, firstNonNA)) {
if(!any(sapply(split, grepl, firstNonNA))) {
return(x)
}

Expand Down
2 changes: 1 addition & 1 deletion R/stoxFunctionAttributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ getVariableNamesStoxData <- function(BioticData, StoxBioticData, ICESBioticData,
# Function to get the names of a table if that table contains certain variables:
getNamesIfVariableIsPresent <- function(table, requiredVariableNames) {
output <- names(table)
if(!requiredVariableNames %in% output) {
if(length(requiredVariableNames) && !requiredVariableNames %in% output) {
output <- NULL
}
return(output)
Expand Down
Loading