Skip to content

Commit

Permalink
Improve warnings from get_RLum() for RLum.Data.Curve objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcol committed Feb 18, 2025
1 parent 3d740c1 commit b6db532
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
38 changes: 11 additions & 27 deletions R/RLum.Data.Curve-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ setAs("data.frame", "RLum.Data.Curve",

setAs("RLum.Data.Curve", "data.frame",
function(from){

data.frame(x = from@data[,1],
y = from@data[,2])

})


Expand All @@ -146,13 +144,11 @@ setAs("matrix", "RLum.Data.Curve",
curveType = NA_character_,
data = from,
info = list())

})

setAs("RLum.Data.Curve", "matrix",
function(from){
from@data

})

# show() --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -281,7 +277,6 @@ setMethod(
newRLumDataCurve@info <- info
newRLumDataCurve@.uid <- .uid
newRLumDataCurve@.pid <- .pid

}
return(newRLumDataCurve)
}
Expand Down Expand Up @@ -311,35 +306,29 @@ setMethod(
setMethod("get_RLum",
signature("RLum.Data.Curve"),
definition = function(object, info.object = NULL) {
.set_function_name("get_RLum")
on.exit(.unset_function_name(), add = TRUE)

##if info.object == NULL just show the curve values
if(!is.null(info.object)) {
if(info.object %in% names(object@info)){
unlist(object@info[info.object])

}else{
##check for entries
if(length(object@info) == 0){
warning("[get_RLum()] This RLum.Data.Curve object has no info objects! NULL returned!)")
return(NULL)

}else{
##grep names
temp.element.names <- paste(names(object@info), collapse = ", ")

warning.text <- paste("[get_RLum()] Invalid info.object name. Valid names are:", temp.element.names)

warning(warning.text, call. = FALSE)
.throw_warning("This RLum.Data.Curve object has no ",
"info objects, NULL returned")
return(NULL)

}

.throw_warning("Invalid 'info.object' name, valid names are: ",
.collapse(names(object@info)))
return(NULL)
}

}else{
object@data

}
} else {
## if info.object == NULL just show the curve values
object@data
}
})


Expand All @@ -360,7 +349,6 @@ setMethod("length_RLum",
"RLum.Data.Curve",
function(object){
max(object@data[,1])

})


Expand All @@ -380,7 +368,6 @@ setMethod("names_RLum",
"RLum.Data.Curve",
function(object){
names(object@info)

})


Expand Down Expand Up @@ -436,9 +423,7 @@ setMethod(f = "bin_RLum.Data",

##just return the object
return(object)

}

})


Expand Down Expand Up @@ -486,7 +471,6 @@ setMethod(
set_RLum(class = "RLum.Data.Curve",
originator = "smooth_RLum",
data = object)

}
)

Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test_RLum.Data.Curve.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ test_that("check class", {

##check get_RLum
object <- set_RLum(class = "RLum.Data.Curve", data = object, info = list(a = "test"))
expect_warning(get_RLum(object, info.object = "est"), regexp = "Invalid info.object name")
expect_warning(get_RLum(object, info.object = "error"),
"Invalid 'info.object' name, valid names are:")

##test names
expect_type(names(object), "character")
Expand Down

0 comments on commit b6db532

Please sign in to comment.