Skip to content

Commit

Permalink
[misc] avoid scientific notation in as.character(rows). closes #1167 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin authored Oct 29, 2024
1 parent a0c4317 commit 03f63eb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# openxlsx2 (development version)

## Fixes

* Previously rows that trigger scientific notation (e.g. `1e+05`) would cause issues, when matched against a non scientific version. [1170](https://github.com/JanMarvin/openxlsx2/pull/1170)


***************************************************************************

Expand Down
10 changes: 5 additions & 5 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -4397,7 +4397,7 @@ wbWorkbook <- R6::R6Class(
private$do_cell_init(sheet, dims)

row_attr <- self$worksheets[[sheet]]$sheet_data$row_attr
sel <- match(as.character(rows), row_attr$r)
sel <- match(as.character(as.integer(rows)), row_attr$r)
sel <- sel[!is.na(sel)]

if (!is.null(heights)) {
Expand Down Expand Up @@ -4441,7 +4441,7 @@ wbWorkbook <- R6::R6Class(
return(invisible(self))
}

sel <- match(as.character(rows), row_attr$r)
sel <- match(as.character(as.integer(rows)), row_attr$r)
sel <- sel[!is.na(sel)]
row_attr[sel, "ht"] <- ""
row_attr[sel, "customHeight"] <- ""
Expand Down Expand Up @@ -4768,7 +4768,7 @@ wbWorkbook <- R6::R6Class(
# get the selection based on the row_attr frame.

# the first n -1 rows get outlineLevel
select <- row_attr$r %in% as.character(rows)
select <- row_attr$r %in% as.character(as.integer(rows))
collapse_in <- ifelse(below, length(rows), 1)
select_n1 <- row_attr$r %in% as.character(rows[-collapse_in])
if (length(select)) {
Expand Down Expand Up @@ -4804,7 +4804,7 @@ wbWorkbook <- R6::R6Class(
row_attr <- self$worksheets[[sheet]]$sheet_data$row_attr

# get the selection based on the row_attr frame.
select <- row_attr$r %in% as.character(rows)
select <- row_attr$r %in% as.character(as.integer(rows))
if (length(select)) {
row_attr$outlineLevel[select] <- ""
row_attr$collapsed[select] <- ""
Expand Down Expand Up @@ -8785,7 +8785,7 @@ wbWorkbook <- R6::R6Class(
}

rows_df <- self$worksheets[[sheet]]$sheet_data$row_attr
sel <- rows_df$r %in% as.character(rows)
sel <- rows_df$r %in% as.character(as.integer(rows))

rows_df$customFormat[sel] <- "1"
rows_df$s[sel] <- styid
Expand Down
2 changes: 1 addition & 1 deletion R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ wb_to_df <- function(
}

if (!is.null(rows)) {
keep_rows <- as.character(rows)
keep_rows <- as.character(as.integer(rows))

if (all(keep_rows %in% rownames(z))) {
z <- z[rownames(z) %in% keep_rows, , drop = FALSE]
Expand Down
4 changes: 2 additions & 2 deletions R/wb_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ delete_data <- function(wb, sheet, cols, rows) {
cc <- wb$worksheets[[sheet_id]]$sheet_data$cc

if (is.numeric(cols)) {
sel <- cc$row_r %in% as.character(rows) & cc$c_r %in% int2col(cols)
sel <- cc$row_r %in% as.character(as.integer(rows)) & cc$c_r %in% int2col(cols)
} else {
sel <- cc$row_r %in% as.character(rows) & cc$c_r %in% cols
sel <- cc$row_r %in% as.character(as.integer(rows)) & cc$c_r %in% cols
}

# clean selected entries of cc
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,26 @@ test_that("set and remove row heights work", {

})

test_that("set and remove row heights work", {

rows <- c(99999, 100000, 100001)

wb <- wb_workbook()$
add_worksheet()$
add_data(x = 1:3, dims = "A99999:A100001")$
set_row_heights(
rows = rows,
heights = c(24, 28, 32)
)

exp <- c("99999", "100000", "100001")
got <- wb$worksheets[[1]]$sheet_data$row_attr$r
expect_equal(exp, got)

wb$remove_row_heights(rows = rows)

})

test_that("add_drawing works", {

skip_if_not_installed("rvg")
Expand Down

0 comments on commit 03f63eb

Please sign in to comment.