R-Lum / Luminescence

Development of the R package 'Luminescence'
https://r-lum.github.io/Luminescence/
GNU General Public License v3.0
15 stars 7 forks source link

Some S3 methods don't work #202

Closed mcol closed 2 months ago

mcol commented 2 months ago

I'm going through the list of S3 methods defined in methods_RLum(). While most work as expected, here are some that generate errors:

## ----------
data(ExampleData.CW_OSL_Curve, envir = environment())
curve <- set_RLum(
    class = "RLum.Data.Curve",
    data = as.matrix(ExampleData.CW_OSL_Curve),
    curveType = "measured",
    recordType = "OSL",
    info = list(a = "test")
)

bin(curve)
# Error in bin(curve) : could not find function "bin"

## ----------
data(ExampleData.XSYG, envir = environment())
spectrum <- TL.Spectrum

bin(spectrum)
# Error in bin(spectrum) : could not find function "bin"

## ----------
data(ExampleData.RLum.Data.Image, envir = environment())
image <- ExampleData.RLum.Data.Image

hist(image)
# Error in get_RLum(x)@data : 
#   no applicable method for `@` applied to an object of class "array"
summary(image)
# Error in object@data@data : 
#   no applicable method for `@` applied to an object of class "array"

The bin() failures are probably due to the fact that there's no existing bin() function in R, so we should set up our own generic.

mcol commented 2 months ago

I have a fix for the bin() errors, but I'm stuck on the other two. The current code is very old, probably it precedes updates to the RLum S4 classes and I can't make sense of what should be expected: https://github.com/R-Lum/Luminescence/blob/759a1142651cc557f9fd06c6b061d1aff244cdf9/R/methods_RLum.R#L152 https://github.com/R-Lum/Luminescence/blob/759a1142651cc557f9fd06c6b061d1aff244cdf9/R/methods_RLum.R#L180

RLumSK commented 2 months ago

OK, this is indeed a left over, because in the past we had used the 'raster' package for the image data. Today the data slot is an array. Now it should read:

hist.RLum.Data.Image <- function(x, ...) hist(x = get_RLum(x), ...) 
hist.RLum.Data.Image <- function(x, ...) summary(x = get_RLum(x), ...) 

Only problem to consider is that the array may have different dimensions. Perhaps we can use a loop for it or add something of set a dimension parameter (image slice).

mcol commented 2 months ago

Do you have an example of such image object?

RLumSK commented 2 months ago
data(ExampleData.RLum.Data.Image, envir = environment())
mcol commented 2 months ago

That's what I'm using, but I think it contains only one array.

mcol commented 2 months ago

I've constructed one like this: image3 <- set_RLum("RLum.Data.Image", data = array(runif(300, 0, 255), c(10, 10, 3))), and the methods work directly without needing loops.

mcol commented 2 months ago

Fixed by #232.