Skip to content

Commit

Permalink
Start using the .validate_logical_scalar() helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcol committed Feb 10, 2025
1 parent 0fcb61f commit 8e237d8
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 74 deletions.
2 changes: 1 addition & 1 deletion R/RLum.Analysis-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ setMethod("get_RLum",
get.index <- FALSE

} else {
.validate_class(get.index, "logical")
.validate_logical_scalar(get.index)
}

##get originator
Expand Down
14 changes: 4 additions & 10 deletions R/calc_MoransI.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ calc_MoransI <- function(object,
.validate_class(object, c("RLum.Results", "numeric", "integer"))
## To add
# - should contain a numerical vector of length 100
.validate_class(spatial_autocorrelation, "logical")

if(is.numeric(object))
{
Expand All @@ -115,16 +114,14 @@ calc_MoransI <- function(object,
# - should be a valid df_neighbour dataframe
}

.validate_class(compute_pseudo_p, "logical")
.validate_logical_scalar(spatial_autocorrelation)
.validate_logical_scalar(compute_pseudo_p)
if (!is.null(tested_moransI)) {
.validate_class(tested_moransI, "numeric")
.validate_length(tested_moransI, 1)
}
.validate_positive_scalar(n_permutations, int = TRUE)
.validate_class(return_intermediate_values, "logical")
## To add
# - should be a single value

.validate_logical_scalar(return_intermediate_values)

## No spatial autocorrelation ---------------------------------------------

Expand Down Expand Up @@ -316,10 +313,7 @@ calc_MoransI <- function(object,
vb_contains_observation <- rep(TRUE, times = 100)


.validate_class(restrict_to_8x8, "logical")
## To add:
## - contains one element

.validate_logical_scalar(restrict_to_8x8)

## Construct the dataframe with borders and weights ---------------------------------

Expand Down
9 changes: 6 additions & 3 deletions R/combine_De_Dr.R
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,12 @@ combine_De_Dr <- function(
.require_suggested_package("coda")
.require_suggested_package("mclust")

# Integrity checks --------------------------------------------------------
if(length(De) != length(s))
.throw_error("'De' and 's' are not of similar length!")
## Integrity checks -------------------------------------------------------

if (length(De) != length(s))
.throw_error("'De' and 's' are not of similar length")
.validate_logical_scalar(verbose)
.validate_logical_scalar(plot)

# Prepare data ------------------------------------------------------------
## we have to fetch the function otherwise
Expand Down
8 changes: 4 additions & 4 deletions R/fit_DoseResponseCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ fit_DoseResponseCurve <- function(
fit.method_supported <- c("LIN", "QDR", "EXP", "EXP OR LIN",
"EXP+LIN", "EXP+EXP", "GOK", "LambertW")
fit.method <- .validate_args(fit.method, fit.method_supported)
.validate_class(fit.force_through_origin, "logical")
.validate_class(fit.weights, "logical")
.validate_class(fit.includingRepeatedRegPoints, "logical")
.validate_class(fit.bounds, "logical")
.validate_logical_scalar(fit.force_through_origin)
.validate_logical_scalar(fit.weights)
.validate_logical_scalar(fit.includingRepeatedRegPoints)
.validate_logical_scalar(fit.bounds)
.validate_positive_scalar(fit.NumberRegPoints, int = TRUE, null.ok = TRUE)
.validate_positive_scalar(fit.NumberRegPointsReal, int = TRUE, null.ok = TRUE)
.validate_positive_scalar(n.MC, int = TRUE)
Expand Down
6 changes: 3 additions & 3 deletions R/plot_DoseResponseCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ plot_DoseResponseCurve <- function(
## Integrity checks -------------------------------------------------------

.validate_class(object, "RLum.Results")
.validate_class(plot_extended, "logical")
.validate_class(plot_singlePanels, "logical")
.validate_class(verbose, "logical")
.validate_logical_scalar(plot_extended)
.validate_logical_scalar(plot_singlePanels)
.validate_logical_scalar(verbose)
.validate_positive_scalar(cex.global)

## Fitting arguments ------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions R/plot_GrowthCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ plot_GrowthCurve <- function(
}

## input validation
.validate_class(output.plot, "logical")
.validate_class(output.plotExtended, "logical")
.validate_class(plot_singlePanels, "logical")
.validate_class(verbose, "logical")
.validate_logical_scalar(output.plot)
.validate_logical_scalar(output.plotExtended)
.validate_logical_scalar(plot_singlePanels)
.validate_logical_scalar(verbose)
.validate_positive_scalar(cex.global)

## remaining input validation occurs inside the fitting function
Expand Down
2 changes: 1 addition & 1 deletion R/plot_RLum.Analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ plot_RLum.Analysis <- function(

##try to find optimal parameters, this is however, a little bit stupid, but
##better than without any presetting
.validate_class(combine, "logical")
.validate_logical_scalar(combine)
if (combine && length(object@records) <= 1) {
combine <- FALSE
.throw_warning("'combine' can't be used with fewer than two curves, ",
Expand Down
19 changes: 5 additions & 14 deletions R/plot_SingleGrainDisc.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,11 @@ plot_SingleGrainDisc <- function(object,
vn_values_to_show <- get_RLum(object)
}

.validate_class(show_coordinates, "logical")
# - should be a single element

.validate_class(show_location_ids, "logical")
# - should be a single element

.validate_class(show_legend, "logical")
# - should be a single element

.validate_class(show_neighbours, "logical")
# - should be a single element

.validate_class(show_positioning_holes, "logical")
# - should be a single element
.validate_logical_scalar(show_coordinates)
.validate_logical_scalar(show_location_ids)
.validate_logical_scalar(show_legend)
.validate_logical_scalar(show_neighbours)
.validate_logical_scalar(show_positioning_holes)

if (is.null(df_neighbours)) {
df_neighbours <- .get_Neighbours(object)
Expand Down
12 changes: 6 additions & 6 deletions R/read_BIN2R.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ read_BIN2R <- function(

## Config -----------------------------------------------------------------

.validate_class(show.raw.values, "logical")
.validate_class(zero_data.rm, "logical")
.validate_class(duplicated.rm, "logical")
.validate_class(fastForward, "logical")
.validate_class(show.record.number, "logical")
.validate_class(txtProgressBar, "logical")
.validate_logical_scalar(show.raw.values)
.validate_logical_scalar(zero_data.rm)
.validate_logical_scalar(duplicated.rm)
.validate_logical_scalar(fastForward)
.validate_logical_scalar(show.record.number)
.validate_logical_scalar(txtProgressBar)
.validate_class(ignore.RECTYPE, c("logical", "numeric"))

##set file_link for internet downloads
Expand Down
3 changes: 2 additions & 1 deletion R/read_Daybreak2R.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ read_Daybreak2R <- function(
# directory and import them, if this is detected, we proceed as list

.validate_class(file, c("character", "list"))
.validate_logical_scalar(verbose)

if(is(file, "character")) {
.validate_not_empty(file)
Expand All @@ -95,7 +96,7 @@ read_Daybreak2R <- function(
read_Daybreak2R(
file = file[[x]],
txtProgressBar = txtProgressBar,
verbose = verbose[1]
verbose = verbose
)
})

Expand Down
4 changes: 2 additions & 2 deletions R/write_R2BIN.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ write_R2BIN <- function(

.validate_class(object, "Risoe.BINfileData")
.validate_class(file, "character")
.validate_class(verbose, "logical")
.validate_class(txtProgressBar, "logical")
.validate_logical_scalar(verbose)
.validate_logical_scalar(txtProgressBar)

## check if it fulfills the latest definition ...
if(ncol(object@METADATA) != ncol(set_Risoe.BINfileData()@METADATA)){
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_RLum.Analysis-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test_that("get_RLum", {
expect_error(get_RLum(tmp, RLum.type = 1L),
"'RLum.type' should be of class 'character'")
expect_error(get_RLum(tmp, get.index = "a"),
"'get.index' should be of class 'logical'")
"'get.index' should be a single logical value")

## check functionality
expect_length(get_RLum(obj, subset = (recordType == "RF")), 2)
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_calc_MoransI.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ test_that("input validation", {
expect_error(calc_MoransI(obj, df_neighbours = "error"),
"'df_neighbours' should be of class 'data.frame'")
expect_error(calc_MoransI(obj, spatial_autocorrelation = "error"),
"'spatial_autocorrelation' should be of class 'logical'")
"'spatial_autocorrelation' should be a single logical value")
expect_error(calc_MoransI(obj, compute_pseudo_p = "error"),
"'compute_pseudo_p' should be of class 'logical'")
"'compute_pseudo_p' should be a single logical value")
expect_error(calc_MoransI(obj, n_permutations = "error"),
"'n_permutations' should be a positive integer scalar")
expect_error(calc_MoransI(obj, return_intermediate_values = "error"),
"'return_intermediate_values' should be of class 'logical'")
"'return_intermediate_values' should be a single logical value")

expect_error(calc_MoransI(c(1, rep(NA, 99)),
spatial_autocorrelation = FALSE),
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_fit_DoseResponseCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ test_that("input validation", {
## other arguments
expect_error(fit_DoseResponseCurve(LxTxData,
fit.force_through_origin = "error"),
"'fit.force_through_origin' should be of class 'logical'")
"'fit.force_through_origin' should be a single logical value")
expect_error(fit_DoseResponseCurve(LxTxData, fit.weights = "error"),
"'fit.weights' should be of class 'logical'")
"'fit.weights' should be a single logical value")
expect_error(fit_DoseResponseCurve(LxTxData,
fit.includingRepeatedRegPoints = "error"),
"'fit.includingRepeatedRegPoints' should be of class 'logical'")
"'fit.includingRepeatedRegPoints' should be a single logical")
expect_error(fit_DoseResponseCurve(LxTxData,
fit.NumberRegPoints = "error"),
"'fit.NumberRegPoints' should be a positive integer scalar")
expect_error(fit_DoseResponseCurve(LxTxData, fit.NumberRegPointsReal = "error"),
"'fit.NumberRegPointsReal' should be a positive integer scalar")
expect_error(fit_DoseResponseCurve(LxTxData,
fit.bounds = "error"),
"'fit.bounds' should be of class 'logical'")
"'fit.bounds' should be a single logical value")
expect_error(fit_DoseResponseCurve(LxTxData,
n.MC = "error"),
"'n.MC' should be a positive integer scalar")
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_plot_DoseResponseCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ test_that("input validation", {
fixed = TRUE)
expect_error(
plot_DoseResponseCurve(fit, plot_extended = "error"),
"'plot_extended' should be of class 'logical'")
"'plot_extended' should be a single logical value")
expect_error(
plot_DoseResponseCurve(fit, plot_singlePanels = "error"),
"'plot_singlePanels' should be of class 'logical'")
"'plot_singlePanels' should be a single logical value")
expect_error(
plot_DoseResponseCurve(fit, verbose = "error"),
"'verbose' should be of class 'logical'")
"'verbose' should be a single logical value")
expect_error(
plot_DoseResponseCurve(fit, cex.global = 0),
"'cex.global' should be a positive scalar")
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_plot_GrowthCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ test_that("input validation", {
"'fit.method' should be one of 'LIN', 'QDR', 'EXP', 'EXP OR LIN'")
expect_error(
plot_GrowthCurve(LxTxData, output.plotExtended = "error"),
"'output.plotExtended' should be of class 'logical'")
"'output.plotExtended' should be a single logical value")
expect_error(
plot_GrowthCurve(LxTxData, plot_singlePanels = "error"),
"'plot_singlePanels' should be of class 'logical'")
"'plot_singlePanels' should be a single logical value")
expect_error(
plot_GrowthCurve(LxTxData, verbose = "error"),
"'verbose' should be of class 'logical'")
"'verbose' should be a single logical value")
expect_error(
plot_GrowthCurve(LxTxData, cex.global = 0),
"'cex.global' should be a positive scalar")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_plot_RLum.Analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test_that("input validation", {
expect_error(plot_RLum.Analysis(temp, ncols = -1),
"'ncols' should be a positive scalar")
expect_error(plot_RLum.Analysis(temp, combine = -1),
"'combine' should be of class 'logical'")
"'combine' should be a single logical value")

expect_error(plot_RLum.Analysis(
set_RLum("RLum.Analysis", records = list(c1@records[[1]],
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test_plot_SingleGrainDisc.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ test_that("input validation", {
expect_error(plot_SingleGrainDisc("error"),
"'object' should be of class 'RLum.Results', 'numeric' or")
expect_error(plot_SingleGrainDisc(obj, show_coordinates = "error"),
"'show_coordinates' should be of class 'logical'")
"'show_coordinates' should be a single logical value")
expect_error(plot_SingleGrainDisc(obj, show_location_ids = "error"),
"'show_location_ids' should be of class 'logical'")
"'show_location_ids' should be a single logical value")
expect_error(plot_SingleGrainDisc(obj, show_legend = "error"),
"'show_legend' should be of class 'logical'")
"'show_legend' should be a single logical value")
expect_error(plot_SingleGrainDisc(obj, show_neighbours = "error"),
"'show_neighbours' should be of class 'logical'")
"'show_neighbours' should be a single logical value")
expect_error(plot_SingleGrainDisc(obj, df_neighbours = "error"),
"'df_neighbours' should be of class 'data.frame'")
expect_error(plot_SingleGrainDisc(obj, df_neighbours = data.frame()),
"'df_neighbours' should be a data frame with 3 columns")
expect_error(plot_SingleGrainDisc(obj, show_positioning_holes = "error"),
"'show_positioning_holes' should be of class 'logical'")
"'show_positioning_holes' should be a single logical value")
expect_error(plot_SingleGrainDisc(obj, str_transform = "error"),
"'str_transform' should be one of 'sqrt', 'lin' or 'log'")

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test_read_BIN2R.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ test_that("input validation", {

## arguments
expect_error(read_BIN2R(bin.v3, show.raw.values = "error"),
"'show.raw.values' should be of class 'logical'")
"'show.raw.values' should be a single logical value")
expect_error(read_BIN2R(bin.v3, zero_data.rm = list(FALSE)),
"'zero_data.rm' should be of class 'logical'")
"'zero_data.rm' should be a single logical value")
expect_error(read_BIN2R(bin.v3, duplicated.rm = "error"),
"'duplicated.rm' should be of class 'logical'")
"'duplicated.rm' should be a single logical value")
expect_error(read_BIN2R(bin.v3, fastForward = "error"),
"'fastForward' should be of class 'logical'")
"'fastForward' should be a single logical value")
expect_error(read_BIN2R(bin.v3, show.record.number = NULL),
"'show.record.number' should be of class 'logical'")
"'show.record.number' should be a single logical value")
expect_error(read_BIN2R(bin.v3, ignore.RECTYPE = "error"),
"'ignore.RECTYPE' should be of class 'logical' or 'numeric'")

Expand Down

0 comments on commit 8e237d8

Please sign in to comment.