tests/testthat/test-writeDataTable.R

test_that("writeDataTable() warns about Excel limitations", {

  dt <- data.frame(var = c(1))
  header_255 <- paste(sample(tolower(LETTERS), 255, TRUE), collapse = "")
  header_256 <- paste(sample(tolower(LETTERS), 256, TRUE), collapse = "")

  wb <- createWorkbook()
  addWorksheet(wb, "sheetA")
  addWorksheet(wb, "sheetB")

  expect_warning({
    colnames(dt) <- header_255
    writeDataTable(wb, sheet = "sheetA", x = dt)
    },
    regexp = NA
  )

  expect_warning({
    colnames(dt) <- header_256
    writeDataTable(wb, sheet = "sheetB", x = dt)
    },
    regexp = "Column name exceeds 255 chars, possible incompatibility with MS Excel. Index: 1"
  )
})

Try the openxlsx package in your browser

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

openxlsx documentation built on Sept. 20, 2024, 5:08 p.m.