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

Improve validation against an Risoe.BINfileData object #516

Merged
merged 1 commit into from
Dec 5, 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
2 changes: 2 additions & 0 deletions R/import_Data.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import_Data <- function (
.set_function_name("import_Data")
on.exit(.unset_function_name(), add = TRUE)

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

## supported functions are extracted automatically from the package
## namespace so that we don't have to maintain this list manually
fun <- grep("^read_", getNamespaceExports("Luminescence"), value = TRUE)
Expand Down
1 change: 1 addition & 0 deletions R/merge_RLum.Analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ merge_RLum.Analysis<- function(

## Integrity checks -------------------------------------------------------

.validate_class(objects, "list")
.validate_not_empty(objects)

##check if object is of class RLum
Expand Down
2 changes: 2 additions & 0 deletions R/merge_RLum.Data.Curve.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ merge_RLum.Data.Curve<- function(

## Integrity checks -------------------------------------------------------

.validate_class(object, "list")

##(1) check if object is of class RLum.Data.Curve
num.objects <- length(object)
temp.recordType.test <- sapply(object, function(x) {
Expand Down
2 changes: 2 additions & 0 deletions R/merge_RLum.Data.Spectrum.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ merge_RLum.Data.Spectrum <- function(

## Integrity checks -------------------------------------------------------

.validate_class(object, "list")

## check if object is of a supported RLum.Data class
num.objects <- length(object)
temp.recordType.test <- sapply(object, function(x) {
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test_import_Data.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
test_that("input validation", {
testthat::skip_on_cran()

expect_error(import_Data(data.frame()),
"'file' should be of class 'character' or 'list'")
expect_message(import_Data(system.file("extdata/QNL84_2_bleached.txt")),
"Unknown file format, nothing imported")
})
Expand Down
8 changes: 2 additions & 6 deletions tests/testthat/test_merge_RLum.Analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ test_that("input validation", {
r1 <- as(object = list(1:10), Class = "RLum.Results")

expect_error(merge_RLum.Analysis(),
"is missing, with no default")
"'objects' should be of class 'list'")
expect_error(merge_RLum.Analysis(o1),
"At least one input object in the list has to be of class")
"'objects' should be of class 'list'")
expect_error(merge_RLum.Analysis(list()),
"'objects' cannot be an empty list")
expect_error(merge_RLum.Analysis(set_RLum("RLum.Analysis")),
"'objects' cannot be an empty RLum.Analysis")
expect_error(merge_RLum.Analysis(set_RLum("RLum.Data.Image")),
"At least one input object in the list has to be of class")
expect_error(merge_RLum.Analysis(list(c1)),
"At least one input object in the list has to be of class")
expect_error(merge_RLum.Analysis(list(o1, "test")),
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test_merge_RLum.Data.Curve.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ test_that("input validation", {
testthat::skip_on_cran()

expect_error(merge_RLum.Data.Curve("", merge.method = "/"),
"'object' should be of class 'list'")
expect_error(merge_RLum.Data.Curve(list("")),
"All elements of 'object' should be of class 'RLum.Data.Curve'")
expect_error(merge_RLum.Data.Curve(list(), merge.method = "/"),
"'object' contains no data")
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test_merge_RLum.Data.Spectrum.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ test_that("input validation", {
testthat::skip_on_cran()

expect_error(merge_RLum.Data.Spectrum("error", merge.method = "/"),
"'object' should be of class 'list'")
expect_error(merge_RLum.Data.Spectrum(list("error")),
"All elements of 'object' should be of class 'RLum.Data.Spectrum'")
expect_error(merge_RLum.Data.Spectrum(list(), merge.method = "-"),
"'object' contains no data")
Expand Down
Loading