Skip to content

Commit 9f723c2

Browse files
committed
[misc] use stringi in inner_update() this is fractions of a ms faster
1 parent 9df565f commit 9f723c2

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ importFrom(grDevices,tiff)
164164
importFrom(magrittr,"%>%")
165165
importFrom(stringi,stri_c)
166166
importFrom(stringi,stri_encode)
167+
importFrom(stringi,stri_extract_first)
167168
importFrom(stringi,stri_isempty)
168169
importFrom(stringi,stri_join)
169170
importFrom(stringi,stri_match)

R/class-style_mgr.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ style_mgr <- R6::R6Class("wbStylesMgr", {
469469
if (skip_duplicates && is_tabSty && style_name[sty] %in% self$tableStyle$name) next
470470

471471
if (is_numfmt) {
472-
typ <- "numFmt"
472+
typ <- "numFmt"
473473
id <- unname(unlist(xml_attr(style[sty], "numFmt"))["numFmtId"])
474474
self$styles$numFmts <- c(self$styles$numFmts, style[sty])
475475
}

R/openxlsx2-package.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#' @import R6
1313
#' @importFrom grDevices bmp col2rgb colors dev.copy dev.list dev.off jpeg png rgb tiff
1414
#' @importFrom magrittr %>%
15-
#' @importFrom stringi stri_c stri_encode stri_isempty stri_join stri_match
16-
#' stri_match_all_regex stri_order stri_opts_collator stri_pad_left
17-
#' stri_rand_strings stri_read_lines stri_replace_all_fixed
15+
#' @importFrom stringi stri_c stri_encode stri_extract_first stri_isempty
16+
#' stri_join stri_match stri_match_all_regex stri_order stri_opts_collator
17+
#' stri_pad_left stri_rand_strings stri_read_lines stri_replace_all_fixed
1818
#' stri_split_fixed stri_split_regex stri_sub stri_unescape_unicode
1919
#' stri_unique
2020
#' @importFrom utils download.file head menu read.csv unzip

R/write.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ inner_update <- function(
6262
# create missing cells
6363
cc_missing <- create_char_dataframe(names(cc), length(missing_cells))
6464
cc_missing$r <- missing_cells
65-
cc_missing$row_r <- gsub("[[:upper:]]", "", cc_missing$r)
66-
cc_missing$c_r <- gsub("[[:digit:]]", "", cc_missing$r)
65+
cc_missing$row_r <- stringi::stri_extract_first(missing_cells, regex = "[0-9]+")
66+
cc_missing$c_r <- stringi::stri_extract_first(missing_cells, regex = "[A-Z]+")
6767

6868
# assign to cc
6969
cc <- rbind(cc, cc_missing)

tests/testthat/test-save.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,22 +215,22 @@ test_that("writing NA, NaN and Inf", {
215215
wb$add_worksheet("Test3")$add_data(x = x, na.strings = "N/A")$save(tmp)
216216

217217
exp <- c(NA, "s", "s", "s")
218-
got <- df_to_char(attr(wb_to_df(tmp, "Test1", keep_attributes = TRUE), "tt")))
218+
got <- df_to_char(attr(wb_to_df(tmp, "Test1", keep_attributes = TRUE), "tt"))
219219
expect_equal(exp, got)
220220

221221
exp <- c("N/A", "#NUM!", "#NUM!", "#VALUE!")
222-
got <- df_to_char(wb_to_df(tmp, "Test2", keep_attributes = TRUE)))
222+
got <- df_to_char(wb_to_df(tmp, "Test2", keep_attributes = TRUE))
223223
expect_equal(exp, got)
224224

225225
wb$clone_worksheet("Test1", "Clone1")$add_data(x = x, na.strings = NULL)$save(tmp)
226226
wb$clone_worksheet("Test3", "Clone3")$add_data(x = x, na.strings = "N/A")$save(tmp)
227227

228228
exp <- c(NA, "s", "s", "s")
229-
got <- df_to_char(attr(wb_to_df(tmp, "Test1", keep_attributes = TRUE), "tt")))
229+
got <- df_to_char(attr(wb_to_df(tmp, "Test1", keep_attributes = TRUE), "tt"))
230230
expect_equal(exp, got)
231231

232232
exp <- c("N/A", "#NUM!", "#NUM!", "#VALUE!")
233-
got <- df_to_char(wb_to_df(tmp, "Test2")))
233+
got <- df_to_char(wb_to_df(tmp, "Test2"))
234234
expect_equal(exp, got)
235235

236236
})

0 commit comments

Comments
 (0)