tests/testthat/test-plot_lucid_1_layer.R

# Heavy: fits LUCID models; runs locally and in CI, not on CRAN.
skip_on_cran()

# test plot_lucid function

test_that("check whether plot_lucid function could work", {
  # run LUCID model
  G <- sim_data$G[1:200, ]
  Z <- sim_data$Z[1:200, ]
  Y_normal <- sim_data$Y_normal[1:200, ]
  cov <- sim_data$Covariate[1:200, ]
  X <- sim_data$X[1:200]
  i <- 1008
  invisible(capture.output(fit1 <- est_lucid(G = G,
                                             Z = Z,
                                             Y = Y_normal,
                                             lucid_model = "early",
                                             CoY = cov,
                                             family = "normal",
                                             K = 2,
                                             seed = i)))
  plot1 <- plot(fit1)
  plot2 <- plot(fit1, G_color = "black", X_color = "red",
                      pos_link_color = "green", fontsize = 10)
  expect_equal(class(plot1), c("sankeyNetwork", "htmlwidget"))
  expect_equal(class(plot2), c("sankeyNetwork", "htmlwidget"))
})

test_that("plot.early_lucid rejects a non-early_lucid object with a clear message", {
  # Previously the only plot method with zero input validation. Since S3
  # dispatch through plot() already guarantees inherits(x, "early_lucid"),
  # this guards a direct call to the method (an exported function, so nothing
  # stops that) with a malformed object, matching pred_lucid()'s own defensive
  # class checks.
  expect_error(plot.early_lucid(structure(list(), class = "lm")),
               "must be a fitted early_lucid model")
  expect_error(plot.early_lucid(structure(list(), class = "lucid_parallel")),
               "must be a fitted early_lucid model")
})

Try the LUCIDus package in your browser

Any scripts or data that you put into this service are public.

LUCIDus documentation built on Sept. 3, 2026, 1:06 a.m.