tests/testthat/test-distinct.R

test_that("uniquerows returns unique rows", {
  out <- uniquerows(mtcars, cols = "cyl")

  expect_s3_class(out, "basetable")
  expect_equal(nrow(out), length(unique(mtcars$cyl)))
})

test_that("uniquerows with no cols returns unique rows of the whole table", {
  df <- data.frame(a = c(1, 1, 2), b = c("x", "x", "y"))

  out <- uniquerows(df)

  expect_equal(nrow(out), 2L)
})

test_that("uniquerows does not mutate its input", {
  input <- data.frame(id = c(1L, 1L, 2L), value = c(3, 3, 1))
  original <- input

  uniquerows(input)

  expect_identical(input, original)
})

Try the basetable package in your browser

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

basetable documentation built on Sept. 18, 2026, 9:13 a.m.