diff --git a/DESCRIPTION b/DESCRIPTION index 429520f..0b9cc26 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: readODS Type: Package Title: Read and Write ODS Files -Version: 2.2.0 +Version: 2.2.0.999 Authors@R: c(person("Gerrit-Jan", "Schutten", role = c("aut"), email = "phonixor@gmail.com"), person("Chung-hong", "Chan", role = c("aut", "cre"), email = "chainsawtiney@gmail.com", comment = c(ORCID = "0000-0002-6232-7530")), diff --git a/NEWS.md b/NEWS.md index fe21d1d..7b6a774 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# readODS 2.2.0.999 + +## Bug fixes + +* Fix #185 - `trim_ws` for `colnames` behaves the same as `readxl::read_xlsx()`. + # readODS 2.2.0 * Fix #151 - Now `read_ods()` and `list_ods_sheets()` can also be used to process flat ods files. `read_fods()` and `list_fods_sheets()` are still available, but not as the so-called "common interface." diff --git a/R/read_ods.R b/R/read_ods.R index 0eea24f..147bbe5 100644 --- a/R/read_ods.R +++ b/R/read_ods.R @@ -253,6 +253,9 @@ if (strings_as_factors) { res <- .convert_strings_to_factors(df = res) } + if (trim_ws && ncol(res) >= 1) { + colnames(res) <- stringi::stri_trim_both(colnames(res)) + } if (as_tibble) { res <- tibble::as_tibble(x = res, .name_repair = .name_repair) } diff --git a/tests/testdata/spaces_colnames.ods b/tests/testdata/spaces_colnames.ods new file mode 100644 index 0000000..a924d16 Binary files /dev/null and b/tests/testdata/spaces_colnames.ods differ diff --git a/tests/testthat/test_read_ods.R b/tests/testthat/test_read_ods.R index 728bcfb..b917f6a 100644 --- a/tests/testthat/test_read_ods.R +++ b/tests/testthat/test_read_ods.R @@ -124,6 +124,11 @@ test_that("trim_ws", { expect_equal(read_ods("../testdata/leadingspaces.ods", trim_ws = TRUE)[1,1, drop = TRUE], "abc") }) +test_that("trim_ws and colnames #185", { + expect_equal(colnames(read_ods("../testdata/spaces_colnames.ods", trim_ws = TRUE)), "abc") + expect_equal(colnames(read_ods("../testdata/spaces_colnames.ods", trim_ws = FALSE)), " abc ") +}) + ## V2.0.0 behavior: backward compatibility test_that("Single column ODS v2.0.0", {