tests/testthat/test-w2l_split.R

# WARNING - Generated by {fusen} from dev/flat_reshape.Rmd: do not edit by hand # nolint: line_length_linter.

test_that("w2l_split names match the content of each element", {
  res <- w2l_split(mtcars, cols = "mpg", by = c("am", "vs"), sep = "|")
  for (nm in names(res)) {
    k <- strsplit(nm, "|", fixed = TRUE)[[1]]
    expect_true(all(mtcars$mpg[mtcars$am == k[2] & mtcars$vs == k[3]] %in% res[[nm]]$value))
  }
  expect_false(any(c("variable", "am", "vs") %in% names(res[[1]])))
})

test_that("w2l_split honours out_type and leaves the input untouched", {
  df <- data.frame(a = 1:4, g = c("x", "x", "y", "y"))
  res <- w2l_split(df, by = "g", out_type = "df")
  expect_identical(names(res), c("x", "y"))
  expect_s3_class(res$x, "data.frame", exact = TRUE)
  expect_identical(class(df), "data.frame")
})

Try the mintyr package in your browser

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

mintyr documentation built on Oct. 5, 2026, 5:08 p.m.