Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #185 #186

Merged
merged 2 commits into from
Apr 15, 2024
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
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
Loading