diff --git a/NEWS.Rmd b/NEWS.Rmd index c0e4e0eb8..60935b3e3 100644 --- a/NEWS.Rmd +++ b/NEWS.Rmd @@ -162,6 +162,8 @@ with all other functions in the package (#411, fixed in #412). in #408). * The produced `RLum.Results` object now also contains a column for the grain (#553, fixed in #554). +* The function now checks that the `sequence.structure` argument contains +at least one IR step (#579, fixed in #580). ### `analyse_SAR.CWOSL()` * Option `plot.single` has been renamed to `plot_singlePanels` (#351, fixed diff --git a/NEWS.md b/NEWS.md index fbe19166c..a88276c46 100644 --- a/NEWS.md +++ b/NEWS.md @@ -185,6 +185,8 @@ fixed in \#408). - The produced `RLum.Results` object now also contains a column for the grain (#553, fixed in \#554). +- The function now checks that the `sequence.structure` argument + contains at least one IR step (#579, fixed in \#580). ### `analyse_SAR.CWOSL()` diff --git a/R/analyse_pIRIRSequence.R b/R/analyse_pIRIRSequence.R index 0fc3bf69f..182d885d0 100644 --- a/R/analyse_pIRIRSequence.R +++ b/R/analyse_pIRIRSequence.R @@ -247,18 +247,22 @@ analyse_pIRIRSequence <- function( .validate_class(object, "RLum.Analysis", extra = "'list'") - ##CHECK ALLOWED VALUES IN SEQUENCE STRUCTURE - temp.collect.invalid.terms <- paste(sequence.structure[ - (!grepl("TL",sequence.structure)) & - (!grepl("IR",sequence.structure)) & - (!grepl("OSL",sequence.structure)) & - (!grepl("EXCLUDE",sequence.structure))], - collapse = ", ") - - if(temp.collect.invalid.terms != ""){ - .throw_error("'", temp.collect.invalid.terms, - "' not allowed in 'sequence.structure'") - } + ## there must be at least an IR step + if (!any(grepl("IR", sequence.structure))) { + .throw_error("'sequence.structure' should contain at least one IR step") + } + + ## check allowed values in sequence structure + temp.collect.invalid.terms <- .collapse( + sequence.structure[!grepl("TL", sequence.structure) & + !grepl("IR", sequence.structure) & + !grepl("OSL", sequence.structure) & + !grepl("EXCLUDE", sequence.structure)]) + + if (temp.collect.invalid.terms != "") { + .throw_error(temp.collect.invalid.terms, + " not allowed in 'sequence.structure'") + } ## deprecated argument if ("plot.single" %in% names(list(...))) { @@ -398,8 +402,8 @@ analyse_pIRIRSequence <- function( temp.IRSL.layout.vector.first <- c(3,5,6,7,3,5,6,8) ## middle (any other Lx,Ln) + temp.IRSL.layout.vector.middle <- NULL if (n.loops > 2) { - temp.IRSL.layout.vector.middle <- vapply(2:(n.loops - 1), FUN = function(x) 5 * x - 1 + c(0:3, 0:2, 4), @@ -407,36 +411,14 @@ analyse_pIRIRSequence <- function( ) } - ##last (Lx,Ln and legend) - temp.IRSL.layout.vector.last <- c( - ifelse(n.loops > 2,max(temp.IRSL.layout.vector.middle) + 1, - max(temp.IRSL.layout.vector.first) + 1), - ifelse(n.loops > 2,max(temp.IRSL.layout.vector.middle) + 2, - max(temp.IRSL.layout.vector.first) + 2), - ifelse(n.loops > 2,max(temp.IRSL.layout.vector.middle) + 4, - max(temp.IRSL.layout.vector.first) + 4), - ifelse(n.loops > 2,max(temp.IRSL.layout.vector.middle) + 5, - max(temp.IRSL.layout.vector.first) + 5), - ifelse(n.loops > 2,max(temp.IRSL.layout.vector.middle) + 1, - max(temp.IRSL.layout.vector.first) + 1), - ifelse(n.loops > 2,max(temp.IRSL.layout.vector.middle) + 2, - max(temp.IRSL.layout.vector.first) + 2), - ifelse(n.loops > 2,max(temp.IRSL.layout.vector.middle) + 4, - max(temp.IRSL.layout.vector.first) + 4), - ifelse(n.loops > 2,max(temp.IRSL.layout.vector.middle) + 6, - max(temp.IRSL.layout.vector.first) + 6)) - - ##options for different sets of curves - if(n.loops > 2){ + ## last (Lx, Ln and legend) + temp.IRSL.layout.vector.last <- c(1, 2, 4, 5, 1, 2, 4, 6) + + (if (n.loops > 2) max(temp.IRSL.layout.vector.middle) + else max(temp.IRSL.layout.vector.first)) temp.IRSL.layout.vector <- c(temp.IRSL.layout.vector.first, temp.IRSL.layout.vector.middle, temp.IRSL.layout.vector.last) - }else{ - - temp.IRSL.layout.vector <- c(temp.IRSL.layout.vector.first, - temp.IRSL.layout.vector.last) - } ##get layout information def.par <- par(no.readonly = TRUE) diff --git a/tests/testthat/test_analyse_pIRIRSequence.R b/tests/testthat/test_analyse_pIRIRSequence.R index 53854adf5..d937aaf8c 100644 --- a/tests/testthat/test_analyse_pIRIRSequence.R +++ b/tests/testthat/test_analyse_pIRIRSequence.R @@ -150,7 +150,14 @@ test_that("input validation", { signal.integral.max = 2, background.integral.min = 900, background.integral.max = 1000, - sequence.structure = "error"), + sequence.structure = "TL"), + "'sequence.structure' should contain at least one IR step") + expect_error(analyse_pIRIRSequence(object, + signal.integral.min = 1, + signal.integral.max = 2, + background.integral.min = 900, + background.integral.max = 1000, + sequence.structure = c("IR50", "error")), "'error' not allowed in 'sequence.structure'") SW({