Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/write_ods.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#' @param na_as_string logical, TRUE indicates that NAs are written as string; FALSE indicates that NAs are written as empty cells.
#' @param padding logical, TRUE indicates that the sheet is padded with repeated empty cells to the maximum size, either 2^20 x 1024 (if the number of columns of `x` is less than or equal 1024) or 2^20 x 16,384 (otherwise). This is the default behaviour of Microsoft Excel. Default is FALSE
#' @return An ODS file written to the file path location specified by the user. The value of \code{path} is also returned invisibly.
#' @details This function emulates [writexl::write_xlsx()] and [openxlsx::write.xlsx()] except in the handling of list columns. The expected behaviour for this is undefined and the two functions behave differently. This function handles list columns by converting them to character vectors of R code (similar to the output of [dput()]), which is probably not ideal.
#' @author Detlef Steuer <steuer@@hsu-hh.de>, Thomas J. Leeper <thosjleeper@@gmail.com>, John Foster <john.x.foster@@nab.com.au>, Chung-hong Chan <chainsawtiney@@gmail.com>
#' @examples
#' \dontrun{
Expand Down
3 changes: 3 additions & 0 deletions man/write_ods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tests/testthat/test_write_ods.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,26 @@ test_that("edge cases 0 x 0 with column info #142", {
expect_error(filename <- write_ods(zero_rows, col_names = FALSE), NA)
expect_true(nrow(suppressWarnings(read_ods(filename, col_names = FALSE))) == 0)
})

test_that("edge cases rownames / colnames only, no data, #142", {
all_na <- mtcars[,c(1,2), drop = FALSE]
all_na[,1] <- NA
all_na[,2] <- NA
expect_error(filename <- write_ods(all_na), NA)
expect_true(nrow(suppressMessages(read_ods(filename, col_names = FALSE))) == 1)
expect_error(filename <- write_ods(all_na, col_names = FALSE), NA)
expect_true(nrow(suppressWarnings(read_ods(filename, col_names = FALSE))) == 0)
expect_error(filename <- write_ods(all_na, row_names = TRUE), NA)
expect_equal(dim(suppressMessages(read_ods(filename, col_names = FALSE))), dim(all_na) + 1)
## just rownames
expect_error(filename <- write_ods(all_na, row_names = TRUE, col_names = FALSE), NA)
expect_equal(nrow(suppressMessages(read_ods(filename, col_names = FALSE))), nrow(all_na))
})

test_that("edge case, list-columns #142", {
## no one knows how list-columns should be dealt with.
## just process them with no errors
lc_test <- tibble::tibble(mtcars)
lc_test$lc <- strsplit(rownames(mtcars), " ")
expect_error(write_ods(lc_test), NA)
})