tests/testthat/test-export_nest.R

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

test_that("export_nest writes one file per row and returns the paths", {
  out <- file.path(tempdir(), "test_export_nest")
  on.exit(unlink(out, recursive = TRUE))
  nd <- w2l_nest(iris, cols = 1:2, by = "Species")
  files <- suppressMessages(export_nest(nd, path = out))
  expect_length(files, 6L)
  expect_true(all(file.exists(files)))
})

test_that("export_nest refuses to overwrite files of other rows", {
  out <- file.path(tempdir(), "test_export_nest_dup")
  on.exit(unlink(out, recursive = TRUE))
  nd <- w2l_nest(iris, cols = 1:2, by = "Species")
  expect_error(suppressMessages(export_nest(nd, by = "Species", path = out)),
               "uniquely identify")
})

test_that("export_nest sanitises group values", {
  out <- file.path(tempdir(), "test_export_nest_safe")
  on.exit(unlink(out, recursive = TRUE))
  nd <- data.table::data.table(g = c("a/b", ".."), data = list(iris[1:2, ], iris[3:4, ]))
  files <- suppressMessages(export_nest(nd, path = out))
  expect_identical(basename(dirname(files)), c("a_b", "unnamed"))
})

test_that("export_nest writes plain, unquoted text with explicit NA", {
  out <- file.path(tempdir(), "test_export_nest_na")
  on.exit(unlink(out, recursive = TRUE))
  nd <- data.table::data.table(g = "x", data = list(data.frame(a = c(1, NA), b = c("u", "v"))))
  f <- suppressMessages(export_nest(nd, path = out))
  expect_identical(readLines(f), c("a\tb", "1\tu", "NA\tv"))
  f <- suppressMessages(export_nest(nd, path = out, na = "-9999", col.names = FALSE))
  expect_identical(readLines(f), c("1\tu", "-9999\tv"))
  expect_error(suppressMessages(export_nest(nd, path = out, sep = ";")), "dedicated")
})

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.