# ============================================================ # Common helper utilities for ecoPointXAI tests # ============================================================ skip_if_no_pkg <- function(pkg) { if (!requireNamespace(pkg, quietly = TRUE)) { skip(paste("Package", pkg, "not installed")) } } # Small synthetic voxel dataset for repeated use vox_small <- data.frame( X = runif(100, 0, 10), Y = runif(100, 0, 10), Z = runif(100, 0, 10), value = runif(100) ) # ============================================================ # 🧩 CRAN safety and torch availability checks # ============================================================ # 1️⃣ Detect if this is a CRAN check environment is_cran_check <- Sys.getenv("_R_CHECK_PACKAGE_NAME_") == "ecoPointXAI" # 2️⃣ Helper: Skip tests safely if torch backend not available skip_if_no_torch <- function() { skip_if_no_pkg("torch") # Skip if torch is installed but backend missing if (requireNamespace("torch", quietly = TRUE)) { if (!torch::torch_is_installed()) { skip("Torch backend (Lantern) not available on this system.") } } # Skip all heavy tests on CRAN (headless build) if (is_cran_check) { skip("Skipping torch-dependent test on CRAN.") } } # 3️⃣ Display diagnostic message once at load if (is_cran_check) { message("⚙️ CRAN check detected — torch-based tests will be skipped safely.") }