Skip to content

Commit

Permalink
Fixed suggests dependent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvin Fuglebakk authored and Edvin Fuglebakk committed Jan 11, 2024
1 parent 574d3ce commit bf4e386
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 54 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ jobs:
shell: Rscript {0}

# turn off testing of suggestions for configurations where Reca is not provided in StoX package repositories
- name: Check without suggested dependencies
- name: Check without suggest-dependencies
if: runner.os == 'macOS' && (matrix.config.r== 'next' || matrix.config.r== '4.3')
env:
_R_CHECK_CRAN_INCOMING_: false
_R_CHECK_FORCE_SUGGESTS_ : false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "error", check_dir = "check")
shell: Rscript {0}

- name: Check with suggested dependencies
- name: Check with suggest-dependencies
if: runner.os != 'macOS' || (matrix.config.r!= 'next' && matrix.config.r!= '4.3')
env:
_R_CHECK_CRAN_INCOMING_: false
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
push:
branches:
- master
- testing
pull_request:
branches:
- testing
Expand Down
6 changes: 6 additions & 0 deletions R/RecaWrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,9 @@ rEcaDataReport <- function(samples, landings, covariates){
out <- data.table::as.data.table(out)
return(out)
}

#' Runs Reca::eca.estimate. Provided so that tinytest unittest can be implemented in a way that is dependent on Reca being available
#' @noRd
eca.estimate <- function(AgeLength, WeightLength, Landings, GlobalParameters){
return(Reca::eca.estimate(AgeLength, WeightLength, Landings, GlobalParameters))
}
45 changes: 45 additions & 0 deletions inst/tinytest/test-ConvergenceAnalysis.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ECA tests are only run if Reca is installed.
if (nchar(system.file(package="Reca"))>0){
#context("Test StoxReportFunctions: ReportRecaParameterStatistics")
StoxLandingFile <- system.file("testresources","StoxLandingData.rds", package="RstoxFDA")
StoxLandingData <- readRDS(StoxLandingFile)
StoxBioticFile <- system.file("testresources","StoxBioticData.rds", package="RstoxFDA")
StoxBioticData <- readRDS(StoxBioticFile)
StoxBioticData$Individual <- StoxBioticData$Individual[StoxBioticData$Individual$IndividualAge<4,]
StoxBioticData$Haul$Gear <- StoxLandingData$Landing$Gear[c(1:20, 1:20, 1:5)]
StoxBioticData$Station$Area <- StoxLandingData$Landing$Area[c(1:20, 1:20, 1:5)]
prep <- RstoxFDA::PrepareRecaEstimate(StoxBioticData, StoxLandingData, FixedEffects = c(), RandomEffects = c("Gear", "Area"), CellEffect = c("All"), MinAge = 2, MaxAge = 3)

fpath1 <- RstoxFDA:::makeTempDirReca("chain1")
fpath2 <- RstoxFDA:::makeTempDirReca("chain2")
fpath3 <- RstoxFDA:::makeTempDirReca("chain3")

paramOut1 <- RstoxFDA::ParameterizeRecaModels(prep, 10, 50, 1, ResultDirectory = fpath1)
paramOut2 <- RstoxFDA::ParameterizeRecaModels(prep, 10, 50, 1, ResultDirectory = fpath2)

paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut1)
paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut2, paramSummary, AppendReport = TRUE)
expect_true(RstoxFDA::is.ParameterizationSummaryData(paramSummary))

RstoxFDA:::removeTempDirReca(fpath1)
RstoxFDA:::removeTempDirReca(fpath2)
RstoxFDA:::removeTempDirReca(fpath3)

convergence <- RstoxFDA::ReportParameterConvergence(paramSummary)

expect_true(RstoxFDA::is.ParameterConvergenceData(convergence))
expect_true(nrow(convergence$ConvergenceReport) < 433)
expect_true(nrow(convergence$ConvergenceReport) > 0)

#construct three identical chains, should signal convergence
paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut1)
paramOut1$GlobalParameters$GlobalParameters$resultdir="B"
paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut1, paramSummary, AppendReport = T)
paramOut1$GlobalParameters$GlobalParameters$resultdir="C"
paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut1, paramSummary, AppendReport = T)

#context("Check Gelman-Rubin for equal chains")
convergence <- RstoxFDA::ReportParameterConvergence(paramSummary, Tolerance = 0)
expect_equal(nrow(convergence$ConvergenceReport), 433)
expect_true(all(abs(convergence$ConvergenceReport$GelmanRubinR-1)<.1))
}
2 changes: 1 addition & 1 deletion inst/tinytest/test-RecaFormatChecks.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ECA tests are not run for platforms where Reca is not available from StoX repositories.
# ECA tests are only run if Reca is installed.

if (length(system.file(package="Reca"))>0){
if (nchar(system.file(package="Reca"))>0){

StoxLandingFile <- system.file("testresources","StoxLandingData.rds", package="RstoxFDA")
StoxLandingData <- readRDS(StoxLandingFile)
Expand Down
3 changes: 1 addition & 2 deletions inst/tinytest/test-RecaWrap.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ECA tests are not run for platforms where Reca is not available from StoX repositories.
# ECA tests are only run if Reca is installed.

if (length(system.file(package="Reca"))>0){
if (nchar(system.file(package="Reca"))>0){

fishdata <- data.table::as.data.table(readRDS(system.file(package = "RstoxFDA", "testresources", "fishdata.rda")))
landings <- data.table::as.data.table(readRDS(system.file(package = "RstoxFDA", "testresources", "landings.rda")))
Expand Down
2 changes: 1 addition & 1 deletion inst/tinytest/test-StoxAnalysisFunctions.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Tests StoX analysis functions that interfaces Reca.
# ECA tests are only run if Reca is installed.

if (length(system.file(package="Reca"))>0){
if (nchar(system.file(package="Reca"))>0){
#context("Test ParameterizeRecaModels cache")
StoxBioticFile <- system.file("testresources","StoxBioticData.rds", package="RstoxFDA")
StoxBioticData <- readRDS(StoxBioticFile)
Expand Down
3 changes: 3 additions & 0 deletions inst/tinytest/test-StoxDataTypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ expect_true(RstoxFDA:::is.POSIXct(as.POSIXct(Sys.Date())))
expect_true(RstoxFDA:::is.RecaPrediction(RstoxFDA::recaPrediction))

#context("Test is.RecaResult")
# ECA tests are only run if Reca is installed.
if (nchar(system.file(package="Reca"))>0){
suppressWarnings(ex<-RstoxFDA::RunRecaEstimate(RstoxFDA::recaDataExample, 100,100))
expect_true(RstoxFDA:::is.RecaResult(ex))
}
44 changes: 0 additions & 44 deletions inst/tinytest/test-StoxReportFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,6 @@ expect_true(!any(is.na(decomp$MeanWeightByAge$SD)))
expect_true(!any(is.na(decomp$MeanWeightByAge$Low)))
expect_true(!any(is.na(decomp$MeanWeightByAge$High)))

#context("Test StoxReportFunctions: ReportRecaParameterStatistics")
StoxLandingFile <- system.file("testresources","StoxLandingData.rds", package="RstoxFDA")
StoxLandingData <- readRDS(StoxLandingFile)
StoxBioticFile <- system.file("testresources","StoxBioticData.rds", package="RstoxFDA")
StoxBioticData <- readRDS(StoxBioticFile)
StoxBioticData$Individual <- StoxBioticData$Individual[StoxBioticData$Individual$IndividualAge<4,]
StoxBioticData$Haul$Gear <- StoxLandingData$Landing$Gear[c(1:20, 1:20, 1:5)]
StoxBioticData$Station$Area <- StoxLandingData$Landing$Area[c(1:20, 1:20, 1:5)]
prep <- RstoxFDA::PrepareRecaEstimate(StoxBioticData, StoxLandingData, FixedEffects = c(), RandomEffects = c("Gear", "Area"), CellEffect = c("All"), MinAge = 2, MaxAge = 3)

fpath1 <- RstoxFDA:::makeTempDirReca("chain1")
fpath2 <- RstoxFDA:::makeTempDirReca("chain2")
fpath3 <- RstoxFDA:::makeTempDirReca("chain3")

paramOut1 <- RstoxFDA::ParameterizeRecaModels(prep, 10, 50, 1, ResultDirectory = fpath1)
paramOut2 <- RstoxFDA::ParameterizeRecaModels(prep, 10, 50, 1, ResultDirectory = fpath2)

paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut1)
paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut2, paramSummary, AppendReport = TRUE)
expect_true(RstoxFDA::is.ParameterizationSummaryData(paramSummary))

RstoxFDA:::removeTempDirReca(fpath1)
RstoxFDA:::removeTempDirReca(fpath2)
RstoxFDA:::removeTempDirReca(fpath3)

convergence <- RstoxFDA::ReportParameterConvergence(paramSummary)

expect_true(RstoxFDA::is.ParameterConvergenceData(convergence))
expect_true(nrow(convergence$ConvergenceReport) < 433)
expect_true(nrow(convergence$ConvergenceReport) > 0)

#construct three identical chains, should signal convergence
paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut1)
paramOut1$GlobalParameters$GlobalParameters$resultdir="B"
paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut1, paramSummary, AppendReport = T)
paramOut1$GlobalParameters$GlobalParameters$resultdir="C"
paramSummary <- RstoxFDA::ReportRecaParameterStatistics(paramOut1, paramSummary, AppendReport = T)

#context("Check Gelman-Rubin for equal chains")
convergence <- RstoxFDA::ReportParameterConvergence(paramSummary, Tolerance = 0)
expect_equal(nrow(convergence$ConvergenceReport), 433)
expect_true(all(abs(convergence$ConvergenceReport$GelmanRubinR-1)<.1))


#context("Test StoxReportFunctions: ReportRecaCatchStatistics")
predictiondatafile <- system.file("testresources","stocksplitpred.rds", package="RstoxFDA")
catchAtAgeFlat <- readRDS(system.file("testresources", "recaPredictionFlat.rds", package="RstoxFDA"))
Expand Down
5 changes: 3 additions & 2 deletions inst/tinytest/test-ecaOuputputConversion.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# ECA tests are only run if Reca is installed.

if (length(system.file(package="Reca"))>0){
if (nchar(system.file(package="Reca"))>0){

#context("test-StoxAnalysisFunctions: tests RecaResult conversion")
ecaResult <- readRDS(system.file("testresources","ecaResult.rds", package="RstoxFDA"))
Expand Down Expand Up @@ -72,7 +72,8 @@ prep <- RstoxFDA:::PrepareRecaEstimate(StoxBioticData, StoxLandingData, FixedEff
fpath <- RstoxFDA:::makeTempDirReca()
RecaData <- RstoxFDA::convertRecaData(prep, nSamples = 10, burnin = 50, thin=1, resultdir = fpath, delta.age = .001, fitfile = "fit", seed = 42, lgamodel = "log-linear")
sanitizeRecaInput(RecaData$AgeLength, RecaData$WeightLength, RecaData$Landings, RecaData$GlobalParameters, stage="parameterize")
est<-Reca::eca.estimate(RecaData$AgeLength, RecaData$WeightLength, RecaData$Landings, RecaData$GlobalParameters)

est<-RstoxFDA:::eca.estimate(RecaData$AgeLength, RecaData$WeightLength, RecaData$Landings, RecaData$GlobalParameters)
RstoxFDA:::removeTempDirReca(fpath)
}

6 changes: 6 additions & 0 deletions inst/tinytest/test-lengthGroupCollapse.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ECA tests are only run if Reca is installed.

if (nchar(system.file(package="Reca"))>0){

StoxLandingFile <- system.file("testresources","StoxLandingData.rds", package="RstoxFDA")
StoxLandingData <- readRDS(StoxLandingFile)

Expand Down Expand Up @@ -41,3 +45,5 @@ reportCAALwoLength <- RstoxFDA::ReportRecaCatchAtLengthAndAge(results)
expect_equal(nrow(reportCAALwLength$NbyLength), 2158)
expect_equal(nrow(reportCAALwoLength$NbyLength), 26)
expect_equal(sum(reportCAALwoLength$NbyLength$CatchAtLength), sum(reportCAALwLength$NbyLength$CatchAtLength))

}
4 changes: 2 additions & 2 deletions tests/testAgainstStoxPrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library(data.table)

# ECA tests are only run if Reca is installed.

if (length(system.file(package="Reca"))>0){
if (nchar(system.file(package="Reca"))>0){


stoxRobj <- readRDS(system.file(package = "RstoxFDA", "testresources", "oldstoxprepreca"))
Expand Down Expand Up @@ -43,4 +43,4 @@ tabStox <- RstoxFDA::makeResultTableRECA(stoxRecaResults$prediction)

#RstoxFDA::plotCatchAtAge(prepRecaResults$prediction, title="RecaPrep results")
#RstoxFDA::plotCatchAtAge(stoxRecaResults$prediction, title="StoxPrep results")
}
}

0 comments on commit bf4e386

Please sign in to comment.