bcgov / ssdtools

An R package to fit and plot Species Sensitivity Distributions (SSDs)
https://bcgov.github.io/ssdtools/
Apache License 2.0
30 stars 16 forks source link

Give more informative error message when passing weights with Inf value! #346

Open joethorley opened 7 months ago

joethorley commented 7 months ago
  data <- ssddata::ccme_boron

  data$Weight <- 1
  data$Weight[rank(data$Conc) > 6] <- 0

  expect_error(ssd_fit_dists(data, dists="lnorm", weight = "Weight"),
               "^`data` has 22 rows with zero weight in 'Weight'\\.$")

  data$Weight[rank(data$Conc) > 6] <- -1

  expect_error(ssd_fit_dists(data, dists="lnorm", weight = "Weight"),
               "^`data\\$Weight` must have values between 0 and Inf\\.$")

  data$Weight[rank(data$Conc) > 6] <- Inf

  expect_warning(expect_error(ssd_fit_dists(data, dists="lnorm", weight = "Weight"),
               "^All distributions failed to fit\\.$"))