Skip to content

Commit

Permalink
Fix #185 (#186)
Browse files Browse the repository at this point in the history
* Add potential test data files for #185

* Fix #185
  • Loading branch information
chainsawriot authored Apr 15, 2024
1 parent 803775d commit 8f0a330
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Chung-hong", "Chan", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-6232-7530")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
3 changes: 3 additions & 0 deletions R/read_ods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Binary file added tests/testdata/spaces_colnames.ods
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/testthat/test_read_ods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 8f0a330

Please sign in to comment.