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

Do not allow NA as column name #316

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* `writeData()` calls `force(x)` to evaluate the object before options are set ([#264](https://github.com/ycphs/openxlsx/issues/264))
* `createComment()` now correctly handles `integers` in `width` and `height` ([#275](https://github.com/ycphs/openxlsx/issues/275))
* `setStyles()` accepts `halign="justify"` ([#305](https://github.com/ycphs/openxlsx/issues/305))
* `data.frame`s with `NA` column names are converted to `"NA"` when saving ([#292](https://github.com/ycphs/openxlsx/issues/292), [#316](https://github.com/ycphs/openxlsx/issues/316)

# openxlsx 4.2.4

Expand Down
2 changes: 2 additions & 0 deletions R/writeData.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ writeData <- function(
) {

x <- force(x)
# transforms NA to "NA" for bad names
names(x) <- paste(names(x))

op <- get_set_options()
on.exit(options(op), add = TRUE)
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-writeData.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ test_that("writeData() forces evaluation of x (#264)", {
options(op)
file.remove(wbfile)
})

test_that("colnames with NA are appropriately handled [292]", {
x <- data.frame(a = 1, b = 2)
colnames(x) <- c("a", NA)
wbfile <- temp_xlsx()
wb <- buildWorkbook(x)
wb$worksheets[[1]]$sheet_data
saveWorkbook(wb, wbfile)

# what could I look for
# openXL(wb)
# openXL(wbfile)
# read.xlsx(wbfile)
})