tests/testthat/test-deprecated.R

test_that("old function names are defunct and name the new function", {
  x <- seq(-2, 2, length.out = 20)
  expect_error(lorentzian(x, 0, 0, 1, 1), "'lorentzian\\(\\)' is defunct; use 'lorentzian_profile\\(\\)'")
  expect_error(pseudo_voigt(x, 0, 0, 1, 1, 1), "defunct")
  expect_error(summaryStats(data.frame(a = 1:5)), "summary_stats")
  expect_error(pareto(matrix(1:6, 3)), "pareto_scale")
  expect_error(plotSpec(), "plot_spectra")
  expect_error(boltzmann_plot(), "use 'boltzmann\\(\\)'")
  expect_error(robustBCYJ(), "use 'robust_boxcox\\(\\)' or 'robust_yeojohnson\\(\\)'")
})

test_that("renamed arguments still work, with a deprecation warning", {
  rlang::local_options(lifecycle_verbosity = "warning")
  x <- c(1, 2, NA, 4, 10)
  expect_warning(z <- zscore(x, drop.na = TRUE), "drop_na")
  expect_equal(z, zscore(x, drop_na = TRUE))
  m <- matrix(stats::rnorm(40, 10), 4)
  expect_warning(s <- snv(m, drop.na = FALSE), "drop_na")
  expect_equal(s, snv(m, drop_na = FALSE))
  expect_warning(b <- baseline_als(m, max.iter = 5), "max_iter")
  expect_equal(b, baseline_als(m, max_iter = 5))
  expect_no_warning(baseline_als(m, max_iter = 5))
  p <- c(0.1, 0.5, 0.9)
  expect_warning(q <- tukey_gh(log(p), "q", g = 0.2, h = 0.1, log.p = TRUE), "log_p")
  expect_equal(q, tukey_gh(log(p), "q", g = 0.2, h = 0.1, log_p = TRUE))
  expect_equal(q, tukey_gh(p, "q", g = 0.2, h = 0.1))
  expect_warning(d <- directional_outlyingness(x, cutoff.quantile = 0.9), "cutoff_quantile")
  expect_equal(d, directional_outlyingness(x, cutoff_quantile = 0.9))
  y <- c(0, 0, 0, 1, 5, 3, 9, 2, 6, 4, 8, 7, 1e3)
  expect_warning(d <- directional_outlyingness(y, rmZeroes = TRUE), "rm_zeroes")
  expect_equal(d, directional_outlyingness(y, rm_zeroes = TRUE))
  expect_warning(d <- directional_outlyingness(y, maxRatio = 3), "max_ratio")
  expect_equal(d, directional_outlyingness(y, max_ratio = 3))
  expect_warning(d <- directional_outlyingness(y, precScale = 1e-8), "prec_scale")
  expect_equal(d, directional_outlyingness(y, prec_scale = 1e-8))
})

test_that("k and kmax still give the number of components, with a deprecation warning", {
  rlang::local_options(lifecycle_verbosity = "warning")
  set.seed(1)
  x <- matrix(stats::rnorm(60 * 3), 60) %*% matrix(stats::rnorm(3 * 8), 3) +
    matrix(stats::rnorm(60 * 8, sd = 0.1), 60)
  set.seed(2)
  ref <- robpca(x, ncomp = 2, ncomp_max = 4)
  set.seed(2)
  expect_warning(fit <- robpca(x, k = 2, ncomp_max = 4), "ncomp")
  expect_equal(fit, ref)
  set.seed(2)
  expect_warning(fit <- robpca(x, ncomp = 2, kmax = 4), "ncomp_max")
  expect_equal(fit, ref)
  set.seed(2)
  expect_equal(robpca(x, 2, 4), ref)
  set.seed(2)
  ref <- rospca(x, ncomp = 2)
  set.seed(2)
  expect_warning(fit <- rospca(x, k = 2), "ncomp")
  expect_equal(fit, ref)
  set.seed(2)
  ref <- macropca(x, ncomp = 2, ncomp_max = 3)
  set.seed(2)
  expect_warning(expect_warning(fit <- macropca(x, k = 2, kmax = 3), "ncomp"), "ncomp_max")
  expect_equal(fit, ref)
  set.seed(2)
  ref <- cellpca(x, ncomp = 2, od_cutoff = "chisq")
  set.seed(2)
  expect_warning(fit <- cellpca(x, k = 2, od_cutoff = "chisq"), "ncomp")
  expect_equal(fit, ref)
  pca <- stats::prcomp(x)
  expect_warning(q <- contributions(pca, k = 2), "ncomp")
  expect_equal(q, contributions(pca, ncomp = 2))
  skip_if_not_installed("HotellingEllipse", "1.3.0")
  expect_warning(q <- q_residuals(pca, k = 2), "ncomp")
  expect_equal(q, q_residuals(pca, ncomp = 2))
  expect_equal(q_residuals(pca, 2), q)
  expect_warning(d <- dmodx(pca, k = 2), "ncomp")
  expect_equal(d, dmodx(pca, ncomp = 2))
  expect_warning(t2 <- hotelling_t2(pca, k = 3), "ncomp")
  expect_equal(t2, hotelling_t2(pca, ncomp = 3))
  expect_warning(p <- plot_embedding(pca, hotelling = "all", k = 3), "ncomp")
  expect_match(p$labels$subtitle, "3 components")
})

test_that("average() takes the deprecated .group_by unquoted or as a string", {
  rlang::local_options(lifecycle_verbosity = "warning")
  df <- data.frame(id = c("a", "a", "b"), v = c(1, 3, 5))
  expected <- average(df, id)
  expect_equal(average(df, group_by = "id"), expected)
  expect_warning(a <- average(df, .group_by = id), "group_by")
  expect_equal(a, expected)
  expect_warning(a <- average(df, .group_by = "id"), "group_by")
  expect_equal(a, expected)
  expect_no_warning(average(df["v"]))
})

test_that("gaussian no longer masks stats::gaussian for glm users", {
  expect_false("gaussian" %in% getNamespaceExports("specProc"))
  expect_s3_class(stats::gaussian(), "family")
})

Try the specProc package in your browser

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

specProc documentation built on Nov. 20, 2026, 5:11 p.m.