Skip to content

Commit

Permalink
Merge branch 'jmbarbone-264-numeric-strings'
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Oct 5, 2021
2 parents 5d456f2 + 77b9e46 commit d2f7e03
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Collate:
'CommentClass.R'
'HyperlinkClass.R'
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[#209](/~https://github.com/ychps/openxlsx/issues/209))
* `makeHyperlinkString()` does no longer require a sheet argument ([#57](/~https://github.com/ychps/openxlsx/issues/57), [#58](/~https://github.com/ychps/openxlsx/issues/58))
* improvements in how `openxlsx` creates temporary directories (see [#262](/~https://github.com/ychps/openxlsx/issues/262))

* `writeData()` calls `force(x)` to evaluate the object before options are set ([#264](/~https://github.com/ycphs/openxlsx/issues/264))

# 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 @@ -179,6 +179,8 @@ writeData <- function(
row.names
) {

x <- force(x)

op <- get_set_options()
on.exit(options(op), add = TRUE)

Expand Down
37 changes: 37 additions & 0 deletions tests/testthat/test-writeData.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
test_that("writeData() forces evaluation of x (#264)", {
wbfile <- temp_xlsx()
op <- options(stringsAsFactors = FALSE)

x <- format(123.4)
df <- data.frame(d = format(123.4))
df2 <- data.frame(e = x)

wb <- createWorkbook()
addWorksheet(wb, "sheet")
writeData(wb, "sheet", startCol = 1, data.frame(a = format(123.4)))
writeData(wb, "sheet", startCol = 2, data.frame(b = as.character(123.4)))
writeData(wb, "sheet", startCol = 3, data.frame(c = "123.4"))
writeData(wb, "sheet", startCol = 4, df)
writeData(wb, "sheet", startCol = 5, df2)

saveWorkbook(wb, wbfile)
out <- read.xlsx(wbfile)

# Possibly overkill

with(out, {
expect_identical(a, b)
expect_identical(a, c)
expect_identical(a, d)
expect_identical(a, e)
expect_identical(b, c)
expect_identical(b, d)
expect_identical(b, e)
expect_identical(c, d)
expect_identical(c, e)
expect_identical(d, e)
})

options(op)
file.remove(wbfile)
})

0 comments on commit d2f7e03

Please sign in to comment.