tests/testthat/test-no_outliers.R

test_that("outliers will leave", {
  set.seed(123)
  tdat <- data.frame(x = rlnorm(100, 0, 5))
  notdat <- no_outliers(tdat, x)
  expect_equal(nrow(notdat), 79)
})

test_that("no outliers remain", {
  set.seed(123)
  tdat <- data.frame(x = rlnorm(100, 0, 5))
  notdat <- no_outliers(tdat, x)
  q <- quantile(tdat$x, probs = c(.25, .75), na.rm = TRUE)
  iqr <- IQR(tdat$x)
  otdat <- subset(tdat, tdat$x < (q[1] - 1.5 * iqr) |
                    tdat$x > (q[2] + 1.5 * iqr))
  p <- data.frame(otdat$x %in% notdat$x)
  if (TRUE %in% p) {
    p_out <- TRUE
  } else {
    p_out <- FALSE
  }
  expect_equal(p_out, FALSE)
})

Try the ztils package in your browser

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

ztils documentation built on April 11, 2025, 5:52 p.m.