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

plot_RLum.Data.Spectrum() crashes if bin.cols is set too high #415

Closed mcol closed 1 week ago

mcol commented 1 week ago

These crash:

data(ExampleData.XSYG, envir = environment())
suppressWarnings(plot_RLum.Data.Spectrum(
        TL.Spectrum,
        plot.type = "persp",
        ylim = c(0, 100),
        bin.cols = 3))
# Error in if (size.diff != 0) { : argument is of length zero

suppressWarnings(plot_RLum.Data.Spectrum(
        TL.Spectrum,
        plot.type = "persp",
        ylim = c(0, 100),
        bin.cols = 8))
# Error: [plot_RLum.Data.Spectrum()] Unknown plot type

The examples work if bin.cols = 2; also bin.cols = 3 works if I set ylim = c(0, 200).

mcol commented 1 week ago

These as well:

plot_RLum.Data.Spectrum(
        TL.Spectrum,
        plot.type = "persp",
        xlim = c(0, 100),
        bin.rows = 1)
# Error in col[1:(length(x) - 1)] :
#   only 0's may be mixed with negative subscripts
# In addition: Warning messages:
# 1: In min(x) : no non-missing arguments to min; returning Inf
# 2: In max(x) : no non-missing arguments to max; returning -Inf
# 3: In min(x) : no non-missing arguments to min; returning Inf
# 4: In max(x) : no non-missing arguments to max; returning -Inf

plot_RLum.Data.Spectrum(
        TL.Spectrum,
        plot.type = "persp",
        xlim = c(0, 100),
        bin.rows = 2)
# Error in rowsum.default(m, group = groups) : incorrect length for 'group'
RLumSK commented 1 week ago

I think what happens is that at some point nothing can be binned anymore, I believe we should calculate a maximum number of possible bins and if the uses adds a higher number we reset to max with a warning.

RLumSK commented 1 week ago

Update: I've looked up the code, the internal function .matrix_binning() works correctly for the binning and does not fail. Worst case is that it returns a single row/single column matrix. However, there seems to be an issue with the column and row name reassignment. Course of action:

mcol commented 1 week ago

Thanks, I'll look into .matrix_binning() now.