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

crash in analyse_FadingMeasurement() #175

Closed
mcol opened this issue Aug 27, 2024 · 5 comments
Closed

crash in analyse_FadingMeasurement() #175

mcol opened this issue Aug 27, 2024 · 5 comments

Comments

@mcol
Copy link
Contributor

mcol commented Aug 27, 2024

Using the object object built in test_analyse_FadingMeasurement.R, I can crash the function with a simple call:

  # Create artificial object ------------------------------------------------
  l <- list()
  time <- 0
  for(x in runif(3, 120,130)) {
    irr  <- set_RLum(
        "RLum.Data.Curve",
        data = matrix(c(1:x, rep(1,x)), ncol = 2),
        originator = "read_XSYG2R",
        recordType = "irradiation (NA)",
        curveType = "simulated",
        info = list(
          startDate = format(Sys.time() + time, "%Y%m%d%H%M%S"),
          position = 1)
      )

    lum  <- set_RLum(
        "RLum.Data.Curve",
        data = matrix(c(1:40, exp(-c(1:40)/ x * 10)), ncol = 2),
        originator = "read_XSYG2R",
        recordType = "IRSL",
        curveType = "measured",
        info = list(
          startDate = format(Sys.time() + time + x + 30, "%Y%m%d%H%M%S"),
          position = 1)
      )

    time <- time + x + 60
    l <- c(l, irr, lum)
  }

object <- set_RLum("RLum.Analysis", records = l, originator = "read_XSYG2R")
analyse_FadingMeasurement(object, signal.integral = 1:2, background.integral = 3)

# Error in Tx_data[[x]] : subscript out of bounds

The crash occurs in this bit of code when x = 2 as our object has length(Lx_data) == 2 and length(Tx_data) == 1):

LxTx_table <- merge_RLum(.warningCatcher(lapply(1:length(Lx_data), function(x) {
calc_OSLLxTxRatio(
Lx.data = Lx_data[[x]],
Tx.data = Tx_data[[x]],

@RLumSK What's the best approach? Stopping if length(Lx_data) != length(Tx_data), working only up to the longest common length, or something else again?

@RLumSK
Copy link
Member

RLumSK commented Aug 27, 2024

The best is here to throw a warning when the lengths differ and use the shortest common length.

@mcol mcol added this to the v0.9.25 (autumn CRAN release) milestone Sep 2, 2024
@mcol
Copy link
Contributor Author

mcol commented Sep 2, 2024

Using the shortest common length, the error moves further down:

Error in data.frame(g_value, TC = tc, G_VALUE_2DAYS = g_value_2days[1],  : 
  arguments imply differing number of rows: 1, 0

That occurs because approx() fails, so T_0.5.predict and T_0.5.interpolated are NULL and the T_0.5 data.frame cannot be constructed correctly:

T_0.5.interpolated <- try(approx(x = LxTx_table[["LxTx_NORM"]],
y = LxTx_table[["TIMESINCEIRR_NORM"]],
ties = mean,
xout = 0.5), silent = TRUE)
if(inherits(T_0.5.interpolated, 'try-error')){
T_0.5.predict <- NULL
T_0.5.interpolated <- NULL
}else{
T_0.5.predict <- stats::predict.lm(fit_predict,newdata = data.frame(x = 0.5),
interval = "predict")
}
T_0.5 <- data.frame(
T_0.5_INTERPOLATED = T_0.5.interpolated$y,
T_0.5_PREDICTED = (10^T_0.5.predict[,1])*tc,
T_0.5_PREDICTED.LOWER = (10^T_0.5.predict[,2])*tc,
T_0.5_PREDICTED.UPPER = (10^T_0.5.predict[,2])*tc
)

Would it be OK in case approx() fails to generate directly such a data frame?

T_0.5 <- data.frame(
        T_0.5_INTERPOLATED = NA,
        T_0.5_PREDICTED = NA,
        T_0.5_PREDICTED.LOWER = NA,
        T_0.5_PREDICTED.UPPER = NA
    )

The tests we have pass with that change, but I don't think that we actually test the output in such cases.

@RLumSK
Copy link
Member

RLumSK commented Sep 2, 2024

Yes, this is a good solution!

@mcol
Copy link
Contributor Author

mcol commented Sep 2, 2024

Another problem came up in this snippet of code:

legend.pos = "outside",
main = expression(paste(T[x], " - curves")),
mtext = plot_settings$mtext
)

The evaluation of the expression() term generated this error:

Error in `plot_RLum.Analysis(object = object, subset = NULL, ...)`: object 'x' not found

After a lengthy search, it turns out that using bquote() around the expression makes the error go away and the plot title appears correctly.

@mcol
Copy link
Contributor Author

mcol commented Sep 3, 2024

Fixed by #192.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants