diff --git a/R/class-workbook.R b/R/class-workbook.R
index 099b33033..e47bc5c67 100644
--- a/R/class-workbook.R
+++ b/R/class-workbook.R
@@ -4784,7 +4784,7 @@ wbWorkbook <- R6::R6Class(
pos <- ''
drawingsXML <- stri_join(
- '',
+ "",
pos,
sprintf('', width, height),
genBasePic(imageNo, next_id),
diff --git a/R/class-worksheet.R b/R/class-worksheet.R
index 79230cc42..4b330a2ea 100644
--- a/R/class-worksheet.R
+++ b/R/class-worksheet.R
@@ -174,7 +174,7 @@ wbWorksheet <- R6::R6Class(
if (!is.null(tab_color)) {
tab_color <- xml_node_create("tabColor", xml_attributes = tab_color)
- tabColor <- sprintf('%s', tab_color)
+ tabColor <- sprintf("%s", tab_color)
} else {
tabColor <- character()
}
@@ -280,7 +280,7 @@ wbWorksheet <- R6::R6Class(
if (length(self$cols_attr)) {
paste(c("", self$cols_attr, ""), collapse = "")
},
- '',
+ "",
sep = ""
)
},
diff --git a/R/helper-functions.R b/R/helper-functions.R
index 1dd6384fe..253b160e2 100644
--- a/R/helper-functions.R
+++ b/R/helper-functions.R
@@ -66,7 +66,7 @@ create_hyperlink <- function(sheet, row = 1, col = 1, text = NULL, file = NULL)
}
if (is.null(text)) {
- str <- sprintf('=HYPERLINK(%s)', dest)
+ str <- sprintf("=HYPERLINK(%s)", dest)
} else {
str <- sprintf('=HYPERLINK(%s, \"%s\")', dest, text)
}
diff --git a/R/read.R b/R/read.R
index 364b28af0..4e069d7a9 100644
--- a/R/read.R
+++ b/R/read.R
@@ -331,8 +331,8 @@ wb_to_df <- function(
cc_tab <- unique(cc$c_t)
# bool
- if (any(cc_tab == c("b"))) {
- sel <- cc$c_t %in% c("b")
+ if (any(cc_tab == "b")) {
+ sel <- cc$c_t %in% "b"
cc$val[sel] <- as.logical(as.numeric(cc$v[sel]))
cc$typ[sel] <- "b"
}
diff --git a/R/utils.R b/R/utils.R
index 9ef13c6ac..9214beaeb 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -798,6 +798,7 @@ read_xml_files <- function(x) {
#' @noRd
un_list <- function(x) {
+ # TODO can use `lengths()` when depending on R 4.0
names <- vapply(x, length, NA_integer_)
nams <- NULL
for (i in seq_along(names)) {
diff --git a/tests/testthat/test-class-comment.R b/tests/testthat/test-class-comment.R
index 314605b63..d7e666eb1 100644
--- a/tests/testthat/test-class-comment.R
+++ b/tests/testthat/test-class-comment.R
@@ -181,10 +181,9 @@ test_that("print comment", {
c2 <- create_comment(text = "this is another comment",
author = "Marco Polo")
-
- exp <- "Author: Marco Polo\nText:\n Marco Polo:\nthis is another comment\n\nStyle:\n\n\n\n\nFont name: Aptos Narrow\nFont size: 11\nFont color: #000000\n\n"
got <- capture_output(print(c2), print = TRUE)
- expect_equal(exp, got)
+ exp <- "Author: Marco Polo\nText:\n Marco Polo:\nthis is another comment\n\nStyle:\n\n\n\n\nFont name: Aptos Narrow\nFont size: 11\nFont color: #000000\n\n"
+ expect_equal(got, exp)
})
@@ -330,11 +329,11 @@ test_that("background images work", {
wb$add_comment(dims = "G12", comment = c1, file = tmp2)
wb$add_comment(dims = "G12", sheet = 1, comment = c1, file = tmp2)
- expect_equal(3, length(wb$vml))
- expect_equal(3, length(wb$vml_rels))
- expect_equal(2, length(wb$vml_rels[[1]]))
- expect_true(is.null(wb$vml_rels[[2]]))
- expect_equal(1, length(wb$vml_rels[[3]]))
+ expect_length(wb$vml, 3)
+ expect_length(wb$vml_rels, 3)
+ expect_length(wb$vml_rels[[1]], 2)
+ expect_null(wb$vml_rels[[2]])
+ expect_length(wb$vml_rels[[3]], 1)
})
diff --git a/tests/testthat/test-class-workbook.R b/tests/testthat/test-class-workbook.R
index 9aeb8d021..941715b66 100644
--- a/tests/testthat/test-class-workbook.R
+++ b/tests/testthat/test-class-workbook.R
@@ -16,8 +16,8 @@ test_that("wb_set_col_widths", {
# set column width to 12
expect_silent(wb$set_col_widths("test", widths = 12L, cols = seq_along(mtcars)))
expect_equal(
- "",
- wb$worksheets[[1]]$cols_attr
+ wb$worksheets[[1]]$cols_attr,
+ ""
)
# wrong sheet
@@ -26,8 +26,8 @@ test_that("wb_set_col_widths", {
# reset the column with, we do not provide an option ot remove the column entry
expect_silent(wb$set_col_widths("test", cols = seq_along(mtcars)))
expect_equal(
- "",
- wb$worksheets[[1]]$cols_attr
+ wb$worksheets[[1]]$cols_attr,
+ ""
)
# create column width for column 25
@@ -360,7 +360,7 @@ test_that("clone worksheet", {
wb <- wb_load(fl)
# wb$get_sheet_names() # chartsheet has no named name?
expect_silent(wb$clone_worksheet(1, "Clone 1"))
- expect_true(inherits(wb$worksheets[[5]], "wbChartSheet"))
+ expect_s3_class(wb$worksheets[[5]], "wbChartSheet")
# wb$open()
# clone pivot table and drawing -----------------------------------------
@@ -502,7 +502,7 @@ test_that("add_drawing works", {
add_drawing(xml = tmp, dims = NULL)$
add_drawing(xml = tmp, dims = "L19")
- expect_equal(1L, length(wb$drawings))
+ expect_length(wb$drawings, 1L)
})
@@ -563,7 +563,7 @@ test_that("add_drawing works", {
wb <- wb %>%
wb_add_mschart(dims = "F4:L20", graph = scatter_plot)
- expect_equal(1L, NROW(wb$charts))
+ expect_equal(NROW(wb$charts), 1L)
chart_01 <- ms_linechart(
data = us_indus_prod,
@@ -644,7 +644,7 @@ test_that("add_chartsheet works", {
wb$add_mschart(graph = data_plot)
- expect_equal(1, nrow(wb$charts))
+ expect_equal(nrow(wb$charts), 1)
expect_true(grepl("A & B", wb$charts$chart))
@@ -661,7 +661,7 @@ test_that("add_chartsheet works", {
)
wb$add_mschart(sheet = 2, graph = data_plot)
- expect_equal(2L, nrow(wb$charts))
+ expect_equal(nrow(wb$charts), 2L)
exp <- "xdr:absoluteAnchor"
got <- xml_node_name(unlist(wb$drawings), "xdr:wsDr")
@@ -844,7 +844,7 @@ test_that("numfmt in pivot tables works", {
## Create the workbook and the pivot table
wb <- wb_workbook()$
add_worksheet("Data")$
- add_data(x = df, startCol = 1, startRow = 2)
+ add_data(x = df, start_col = 1, start_row = 2)
df <- wb_data(wb)
wb$add_pivot_table(df, dims = "A3", rows = "cyl", cols = "gear",
@@ -883,7 +883,7 @@ test_that("numfmt in pivot tables works", {
## Create the workbook and the pivot table
wb <- wb_workbook()$
add_worksheet("Data")$
- add_data(x = df, startCol = 1, startRow = 2)
+ add_data(x = df, start_col = 1, start_row = 2)
df <- wb_data(wb)
wb$add_pivot_table(
@@ -954,7 +954,9 @@ test_that("genBaseWorkbook() works", {
"smartTagTypes", "webPublishing", "fileRecoveryPr", "webPublishObjects",
"extLst"
)
- got <- names(genBaseWorkbook())
- expect_equal(exp, got)
+ expect_equal(
+ names(genBaseWorkbook()),
+ exp
+ )
})
diff --git a/tests/testthat/test-cloneWorksheet.R b/tests/testthat/test-cloneWorksheet.R
index ab2a59a99..444588a0c 100644
--- a/tests/testthat/test-cloneWorksheet.R
+++ b/tests/testthat/test-cloneWorksheet.R
@@ -31,8 +31,8 @@ test_that("clone Worksheet with table", {
wb <- wb_workbook()
wb$add_worksheet("Sheet 1")
- wb$add_data_table(sheet = "Sheet 1", x = iris, tableName = "iris")
- wb$add_data_table(sheet = 1, x = mtcars, tableName = "mtcars", startCol = 10)
+ wb$add_data_table(sheet = "Sheet 1", x = iris, table_name = "iris")
+ wb$add_data_table(sheet = 1, x = mtcars, table_name = "mtcars", start_col = 10)
# FIXME a wild drawing2.xml appears in wb$Content_Types
wb$clone_worksheet("Sheet 1", "Clone 1")
@@ -67,7 +67,7 @@ test_that("copy cells", {
add_data(x = mtcars)$
add_fill(dims = "A1:F1", color = wb_color("yellow"))
- dat <- wb_data(wb, dims = "A1:D4", colNames = FALSE)
+ dat <- wb_data(wb, dims = "A1:D4", col_names = FALSE)
# FIXME there is a bug with next_sheet() in clone_worksheets()
wb$
@@ -87,20 +87,20 @@ test_that("copy cells", {
clone_worksheet(old = 1, new = "Clone5")$
copy_cells(data = dat, dims = "A20", as_value = TRUE, as_ref = FALSE, transpose = TRUE)
- got <- wb_data(wb, sheet = 2, dims = "M2:P5", colNames = FALSE)
+ got <- wb_data(wb, sheet = 2, dims = "M2:P5", col_names = FALSE)
expect_equal(dat, got, ignore_attr = TRUE)
- got <- wb_data(wb, sheet = 3, dims = "A20:D23", colNames = FALSE)
+ got <- wb_data(wb, sheet = 3, dims = "A20:D23", col_names = FALSE)
expect_equal(unlist(t(dat)), unlist(got), ignore_attr = TRUE)
exp <- c("'Sheet 1'!A1", "'Sheet 1'!B1", "'Sheet 1'!C1", "'Sheet 1'!D1")
- got <- wb_data(wb, sheet = 4, dims = "A20:D23", colNames = FALSE, showFormula = TRUE)[[1]]
+ got <- wb_data(wb, sheet = 4, dims = "A20:D23", col_names = FALSE, show_formula = TRUE)[[1]]
expect_equal(exp, got)
- got <- wb_data(wb, sheet = 5, dims = "A20:D23", colNames = FALSE)
+ got <- wb_data(wb, sheet = 5, dims = "A20:D23", col_names = FALSE)
expect_equal(dat, got, ignore_attr = TRUE)
- got <- wb_data(wb, sheet = 6, dims = "A20:D23", colNames = FALSE)
+ got <- wb_data(wb, sheet = 6, dims = "A20:D23", col_names = FALSE)
expect_equal(unlist(t(dat)), unlist(got), ignore_attr = TRUE)
})
@@ -170,7 +170,7 @@ test_that("wb_set_header_footer() works", {
test_that("cloning from workbooks works", {
## FIXME these tests should be improved, right now they only check the
- ## existance of a worksheet
+ ## existence of a worksheet
# create a second workbook
wb <- wb_workbook()$
@@ -184,9 +184,8 @@ test_that("cloning from workbooks works", {
wb_in <- wb_load(fl)
wb$clone_worksheet(old = "SUM", new = "SUM", from = wb_in)
- exp <- c("NOT_SUM", "SUM")
got <- wb$get_sheet_names() %>% unname()
- expect_equal(exp, got)
+ expect_equal(got, c("NOT_SUM", "SUM"))
wb$clone_worksheet(old = "SUM", new = "SUM_clone")
exp <- c("NOT_SUM", "SUM", "SUM_clone")
@@ -284,7 +283,8 @@ test_that("cloning column and row styles works", {
wb$worksheets[[1]]$sheet_data$row_attr[2, "customFormat"] <- "1"
wb$worksheets[[1]]$sheet_data$row_attr[2, "s"] <- wb$styles_mgr$get_xf_id("new_styles")
- cols <- openxlsx2:::wb_create_columns(wb, sheet = 1, cols = seq_along(mtcars))
+ # wb_create_columns is an internal function in openxlsx2.
+ cols <- wb_create_columns(wb, sheet = 1, cols = seq_along(mtcars))
cols[cols$min == 11, "style"] <- "1"
wb$worksheets[[1]]$fold_cols(cols)
diff --git a/tests/testthat/test-conditional_formatting.R b/tests/testthat/test-conditional_formatting.R
index f97e8d163..7c0497b3c 100644
--- a/tests/testthat/test-conditional_formatting.R
+++ b/tests/testthat/test-conditional_formatting.R
@@ -695,8 +695,8 @@ test_that("containsBlanks works", {
wb <- wb_workbook()
wb$add_worksheet()
- wb$add_data(x = c(NA, 1, 2, ""), colNames = FALSE, na.strings = NULL)
- wb$add_data(x = c(NA, 1, 2, ""), colNames = FALSE, na.strings = NULL, startCol = 2)
+ wb$add_data(x = c(NA, 1, 2, ""), col_names = FALSE, na.strings = NULL)
+ wb$add_data(x = c(NA, 1, 2, ""), col_names = FALSE, na.strings = NULL, start_col = 2)
wb$add_conditional_formatting(cols = 1, rows = 1:4, type = "containsBlanks")
wb$add_conditional_formatting(cols = 2, rows = 1:4, type = "notContainsBlanks")
@@ -715,7 +715,7 @@ test_that("warning on cols > 2 and dims", {
wb$add_conditional_formatting(
rows = seq_len(nrow(mtcars)),
cols = c(2, 4, 6),
- type = 'between',
+ type = "between",
rule = c(2, 4)
),
"cols > 2, will create range from min to max."
@@ -724,7 +724,7 @@ test_that("warning on cols > 2 and dims", {
wb <- wb_workbook()$add_worksheet()$add_data(x = mtcars)
wb$add_conditional_formatting(
dims = "B2:F5",
- type = 'between',
+ type = "between",
rule = c(2, 4)
)
diff --git a/tests/testthat/test-converters.R b/tests/testthat/test-converters.R
index 0f9e5096d..f23b8e686 100644
--- a/tests/testthat/test-converters.R
+++ b/tests/testthat/test-converters.R
@@ -1,34 +1,28 @@
test_that("int2col", {
- exp <- LETTERS[1:10]
- got <- int2col(1:10)
- expect_equal(exp, got)
-
- expect_error(int2col("a"),
- "x must be numeric.")
-
+ expect_equal(int2col(1:10), LETTERS[1:10])
+ expect_error(int2col("a"), "x must be numeric.")
})
test_that("col2int", {
expect_null(col2int(NULL))
- expect_equal(1, col2int("a"))
- expect_equal(1, col2int(1))
+ expect_equal(col2int("a"), 1)
+ expect_equal(col2int(1), 1)
expect_error(col2int(list()), "x must be character")
- expect_equal(1, col2int("A"))
- expect_equal(c(1, 3, 4), col2int(c("A", "C:D")))
- expect_equal(c(1, 3, 4, 11), col2int(c("A", "C:D", "K")))
- expect_equal(c(1, 3, 4, 11, 27, 28, 29, 30), col2int(c("A", "C:D", "K", "AA:AD")))
+ expect_equal(col2int("A"), 1)
+ expect_equal(col2int(c("A", "C:D")), c(1, 3, 4))
+ expect_equal(col2int(c("A", "C:D", "K")), c(1, 3, 4, 11))
+ expect_equal(col2int(c("A", "C:D", "K", "AA:AD")), c(1, 3, 4, 11, 27, 28, 29, 30))
expect_error(col2int(c("a", NA_character_, "c")), "x contains NA")
})
test_that("get_cell_refs", {
- exp <- c("B1", "C2", "D3")
got <- get_cell_refs(data.frame(1:3, 2:4))
- expect_equal(exp, got)
+ expect_equal(got, c("B1", "C2", "D3"))
expect_error(get_cell_refs(data.frame("a", "a")),
"cellCoords must only contain integers")
@@ -57,12 +51,10 @@ test_that("", {
)
on.exit(options(op), add = TRUE)
- exp <- 10
got <- calc_col_width(wb_workbook()$get_base_font(), 11)
- expect_equal(exp, got)
+ expect_equal(got, 10)
- exp <- 8
got <- calc_col_width(wb_workbook()$get_base_font(), 7)
- expect_equal(exp, got)
+ expect_equal(got, 8)
})
diff --git a/tests/testthat/test-deleting_tables.R b/tests/testthat/test-deleting_tables.R
index ac7881227..2b4e7a127 100644
--- a/tests/testthat/test-deleting_tables.R
+++ b/tests/testthat/test-deleting_tables.R
@@ -2,8 +2,8 @@ test_that("Deleting a Table Object", {
wb <- wb_workbook()
wb$add_worksheet("Sheet 1")
wb$add_worksheet("Sheet 2")
- wb$add_data_table(sheet = "Sheet 1", x = iris, tableName = "iris")
- wb$add_data_table(sheet = 1, x = mtcars, tableName = "mtcars", startCol = 10)
+ wb$add_data_table(sheet = "Sheet 1", x = iris, table_name = "iris")
+ wb$add_data_table(sheet = 1, x = mtcars, table_name = "mtcars", start_col = 10)
# Get table ----
@@ -38,8 +38,8 @@ test_that("Deleting a Table Object", {
## write same tables again ----
- wb$add_data_table(sheet = 1, x = iris, tableName = "iris")
- wb$add_data_table(sheet = 1, x = mtcars, tableName = "mtcars", startCol = 10)
+ wb$add_data_table(sheet = 1, x = iris, table_name = "iris")
+ wb$add_data_table(sheet = 1, x = mtcars, table_name = "mtcars", start_col = 10)
expect_equal(wb$tables$tab_name, c("iris_openxlsx_deleted", "mtcars_openxlsx_deleted", "iris", "mtcars"))
expect_equal(wb$tables$tab_sheet, c(0, 0, 1, 1))
@@ -72,7 +72,7 @@ test_that("Deleting a Table Object", {
))
## wb_remove_tables clears table object and all data
- wb$add_data_table(sheet = 1, x = iris, tableName = "iris", startCol = 1)
+ wb$add_data_table(sheet = 1, x = iris, table_name = "iris", start_col = 1)
temp <- temp_xlsx()
wb_save(wb, temp)
expect_equal(wb$worksheets[[1]]$tableParts, c("", ""), ignore_attr = TRUE)
@@ -104,8 +104,8 @@ test_that("Save and load Table Deletion", {
wb <- wb_workbook()
wb$add_worksheet("Sheet 1")
wb$add_worksheet("Sheet 2")
- wb$add_data_table(sheet = "Sheet 1", x = iris, tableName = "iris")
- wb$add_data_table(sheet = 1, x = mtcars, tableName = "mtcars", startCol = 10)
+ wb$add_data_table(sheet = "Sheet 1", x = iris, table_name = "iris")
+ wb$add_data_table(sheet = 1, x = mtcars, table_name = "mtcars", start_col = 10)
###################################################################################
@@ -134,8 +134,8 @@ test_that("Save and load Table Deletion", {
wb <- wb_workbook()
wb$add_worksheet("Sheet 1")
wb$add_worksheet("Sheet 2")
- wb$add_data_table(sheet = "Sheet 1", x = iris, tableName = "iris")
- wb$add_data_table(sheet = 1, x = mtcars, tableName = "mtcars", startCol = 10)
+ wb$add_data_table(sheet = "Sheet 1", x = iris, table_name = "iris")
+ wb$add_data_table(sheet = 1, x = mtcars, table_name = "mtcars", start_col = 10)
## remove iris and re-write it
wb$remove_tables(sheet = 1, table = "iris")
@@ -158,9 +158,9 @@ test_that("Save and load Table Deletion", {
wb <- wb_workbook()
wb$add_worksheet("Sheet 1")
wb$add_worksheet("Sheet 2")
- wb$add_data_table(sheet = "Sheet 1", x = iris, tableName = "iris")
- wb$add_data_table(sheet = 1, x = mtcars, tableName = "mtcars", startCol = 10)
- wb$add_data_table(sheet = 2, x = mtcars, tableName = "mtcars2", startCol = 3)
+ wb$add_data_table(sheet = "Sheet 1", x = iris, table_name = "iris")
+ wb$add_data_table(sheet = 1, x = mtcars, table_name = "mtcars", start_col = 10)
+ wb$add_data_table(sheet = 2, x = mtcars, table_name = "mtcars2", start_col = 3)
wb$remove_tables(sheet = 1, table = "iris")
wb$remove_tables(sheet = 1, table = "mtcars")
@@ -179,8 +179,8 @@ test_that("Save and load Table Deletion", {
## write tables back in
- wb$add_data_table(sheet = "Sheet 1", x = iris, tableName = "iris")
- wb$add_data_table(sheet = 1, x = mtcars, tableName = "mtcars", startCol = 10)
+ wb$add_data_table(sheet = "Sheet 1", x = iris, table_name = "iris")
+ wb$add_data_table(sheet = 1, x = mtcars, table_name = "mtcars", start_col = 10)
expect_equal(nrow(wb$tables), 3L)
expect_equal(wb$tables$tab_name, c("mtcars2", "iris", "mtcars"))
diff --git a/tests/testthat/test-formulas.R b/tests/testthat/test-formulas.R
index d36e9e930..c4c7d102d 100644
--- a/tests/testthat/test-formulas.R
+++ b/tests/testthat/test-formulas.R
@@ -3,7 +3,7 @@ test_that("load various formulas", {
fl <- testfile_path("formula.xlsx")
wb <- wb_load(fl)
- expect_true(!is.null(wb$metadata))
+ expect_false(is.null(wb$metadata))
cc <- wb$worksheets[[1]]$sheet_data$cc
@@ -45,7 +45,7 @@ test_that("writing formulas with cell metadata works", {
got <- wb$worksheets[[1]]$sheet_data$cc[1, ]
expect_equal(exp, got)
- expect_true(!is.null(wb$metadata))
+ expect_false(is.null(wb$metadata))
})
diff --git a/tests/testthat/test-named_regions.R b/tests/testthat/test-named_regions.R
index ae0ef4276..4c0dc8240 100644
--- a/tests/testthat/test-named_regions.R
+++ b/tests/testthat/test-named_regions.R
@@ -6,7 +6,7 @@ test_that("Maintaining Named Regions on Load", {
wb$add_worksheet("Sheet 2")
## specify region
- wb$add_data(sheet = 1, x = iris, startCol = 1, startRow = 1)
+ wb$add_data(sheet = 1, x = iris, start_col = 1, start_row = 1)
wb$add_named_region(
sheet = 1,
name = "iris",
@@ -18,10 +18,10 @@ test_that("Maintaining Named Regions on Load", {
)
## using write_data 'name' argument
- wb$add_data(sheet = 1, x = iris, name = "iris2", startCol = 10)
+ wb$add_data(sheet = 1, x = iris, name = "iris2", start_col = 10)
## Named region size 1
- wb$add_data(sheet = 2, x = 99, name = "region1", startCol = 3, startRow = 3)
+ wb$add_data(sheet = 2, x = 99, name = "region1", start_col = 3, start_row = 3)
## save file for testing
out_file <- temp_xlsx()
@@ -32,23 +32,23 @@ test_that("Maintaining Named Regions on Load", {
expected = wb_get_named_regions(wb_load(out_file))
)
- df1 <- read_xlsx(wb, namedRegion = "iris")
- df2 <- read_xlsx(out_file, namedRegion = "iris")
+ df1 <- read_xlsx(wb, named_region = "iris")
+ df2 <- read_xlsx(out_file, named_region = "iris")
expect_equal(df1, df2)
- df1 <- read_xlsx(wb, namedRegion = "region1", skipEmptyCols = FALSE)
+ df1 <- read_xlsx(wb, named_region = "region1", skip_empty_cols = FALSE)
expect_s3_class(df1, "data.frame")
expect_equal(nrow(df1), 0)
expect_equal(ncol(df1), 1)
- df1 <- read_xlsx(wb, namedRegion = "region1", colNames = FALSE)
+ df1 <- read_xlsx(wb, named_region = "region1", col_names = FALSE)
expect_s3_class(df1, "data.frame")
expect_equal(nrow(df1), 1)
expect_equal(ncol(df1), 1)
# nonsense
# df1 is a single value and this single value is now used as rowName
- expect_warning(df1 <- read_xlsx(wb, namedRegion = "region1", rowNames = TRUE))
+ expect_warning(df1 <- read_xlsx(wb, named_region = "region1", row_names = TRUE))
expect_s3_class(df1, "data.frame")
expect_equal(nrow(df1), 0)
expect_equal(ncol(df1), 0)
@@ -67,10 +67,10 @@ test_that("Correctly Loading Named Regions Created in Excel", {
# NamedTable refers to Sheet1!$C$5:$D$8
table_f <- read_xlsx(filename,
- namedRegion = "NamedTable"
+ named_region = "NamedTable"
)
table_w <- read_xlsx(wb,
- namedRegion = "NamedTable"
+ named_region = "NamedTable"
)
expect_equal(object = table_f, expected = table_w)
@@ -82,15 +82,15 @@ test_that("Correctly Loading Named Regions Created in Excel", {
# This proeduced an error in an earlier version of the pacage when the object
# wb was passed, but worked correctly when the filename was passed to read_xlsx
cell_f <- read_xlsx(filename,
- namedRegion = "NamedCell",
- colNames = FALSE,
- rowNames = FALSE
+ named_region = "NamedCell",
+ col_names = FALSE,
+ row_names = FALSE
)
cell_w <- read_xlsx(wb,
- namedRegion = "NamedCell",
- colNames = FALSE,
- rowNames = FALSE
+ named_region = "NamedCell",
+ col_names = FALSE,
+ row_names = FALSE
)
expect_equal(object = cell_f, expected = cell_w)
@@ -100,15 +100,15 @@ test_that("Correctly Loading Named Regions Created in Excel", {
# NamedCell2 refers to Sheet1!$C$2:$C$2
cell2_f <- read_xlsx(filename,
- namedRegion = "NamedCell2",
- colNames = FALSE,
- rowNames = FALSE
+ named_region = "NamedCell2",
+ col_names = FALSE,
+ row_names = FALSE
)
cell2_w <- read_xlsx(wb,
- namedRegion = "NamedCell2",
- colNames = FALSE,
- rowNames = FALSE
+ named_region = "NamedCell2",
+ col_names = FALSE,
+ row_names = FALSE
)
expect_equal(object = cell2_f, expected = cell2_w)
@@ -147,7 +147,7 @@ test_that("Missing rows in named regions", {
wb$add_worksheet("Sheet 1")
## create region
- wb$add_data(sheet = 1, x = iris[1:11, ], startCol = 1, startRow = 1)
+ wb$add_data(sheet = 1, x = iris[1:11, ], start_col = 1, start_row = 1)
expect_warning(
delete_data(wb, sheet = 1, cols = 1:2, rows = c(6, 6)),
"'delete_data' is deprecated."
@@ -185,18 +185,18 @@ test_that("Missing rows in named regions", {
######################################################################## from Workbook
## Skip empty rows
- x <- read_xlsx(file = wb, namedRegion = "iris", colNames = TRUE, skipEmptyRows = TRUE)
+ x <- read_xlsx(file = wb, named_region = "iris", col_names = TRUE, skip_empty_rows = TRUE)
expect_equal(dim(x), c(4, 2))
- x <- read_xlsx(file = wb, namedRegion = "iris2", colNames = TRUE, skipEmptyRows = TRUE)
+ x <- read_xlsx(file = wb, named_region = "iris2", col_names = TRUE, skip_empty_rows = TRUE)
expect_equal(dim(x), c(5, 2))
## Keep empty rows
- x <- read_xlsx(file = wb, namedRegion = "iris", colNames = TRUE, skipEmptyRows = FALSE)
+ x <- read_xlsx(file = wb, named_region = "iris", col_names = TRUE, skip_empty_rows = FALSE)
expect_equal(dim(x), c(5, 2))
- x <- read_xlsx(file = wb, namedRegion = "iris2", colNames = TRUE, skipEmptyRows = FALSE)
+ x <- read_xlsx(file = wb, named_region = "iris2", col_names = TRUE, skip_empty_rows = FALSE)
expect_equal(dim(x), c(6, 2))
@@ -205,18 +205,18 @@ test_that("Missing rows in named regions", {
wb_save(wb, temp_file)
## Skip empty rows
- x <- read_xlsx(file = temp_file, namedRegion = "iris", colNames = TRUE, skipEmptyRows = TRUE)
+ x <- read_xlsx(file = temp_file, named_region = "iris", col_names = TRUE, skip_empty_rows = TRUE)
expect_equal(dim(x), c(4, 2))
- x <- read_xlsx(file = temp_file, namedRegion = "iris2", colNames = TRUE, skipEmptyRows = TRUE)
+ x <- read_xlsx(file = temp_file, named_region = "iris2", col_names = TRUE, skip_empty_rows = TRUE)
expect_equal(dim(x), c(5, 2))
## Keep empty rows
- x <- read_xlsx(file = temp_file, namedRegion = "iris", colNames = TRUE, skipEmptyRows = FALSE)
+ x <- read_xlsx(file = temp_file, named_region = "iris", col_names = TRUE, skip_empty_rows = FALSE)
expect_equal(dim(x), c(5, 2))
- x <- read_xlsx(file = temp_file, namedRegion = "iris2", colNames = TRUE, skipEmptyRows = FALSE)
+ x <- read_xlsx(file = temp_file, named_region = "iris2", col_names = TRUE, skip_empty_rows = FALSE)
expect_equal(dim(x), c(6, 2))
unlink(temp_file)
@@ -230,7 +230,7 @@ test_that("Missing columns in named regions", {
wb$add_worksheet("Sheet 1")
## create region
- wb$add_data(sheet = 1, x = iris[1:11, ], startCol = 1, startRow = 1)
+ wb$add_data(sheet = 1, x = iris[1:11, ], start_col = 1, start_row = 1)
expect_warning(
delete_data(wb, sheet = 1, cols = 2, rows = 1:12),
"'delete_data' is deprecated."
@@ -265,18 +265,18 @@ test_that("Missing columns in named regions", {
######################################################################## from Workbook
## Skip empty cols
- x <- read_xlsx(file = wb, namedRegion = "iris", colNames = TRUE, skipEmptyCols = TRUE)
+ x <- read_xlsx(file = wb, named_region = "iris", col_names = TRUE, skip_empty_cols = TRUE)
expect_equal(dim(x), c(4, 1))
- x <- read_xlsx(file = wb, namedRegion = "iris2", colNames = TRUE, skipEmptyCols = TRUE)
+ x <- read_xlsx(file = wb, named_region = "iris2", col_names = TRUE, skip_empty_cols = TRUE)
expect_equal(dim(x), c(4, 2))
## Keep empty cols
- x <- read_xlsx(file = wb, namedRegion = "iris", colNames = TRUE, skipEmptyCols = FALSE)
+ x <- read_xlsx(file = wb, named_region = "iris", col_names = TRUE, skip_empty_cols = FALSE)
expect_equal(dim(x), c(4, 2))
- x <- read_xlsx(file = wb, namedRegion = "iris2", colNames = TRUE, skipEmptyCols = FALSE)
+ x <- read_xlsx(file = wb, named_region = "iris2", col_names = TRUE, skip_empty_cols = FALSE)
expect_equal(dim(x), c(4, 3))
@@ -285,18 +285,18 @@ test_that("Missing columns in named regions", {
wb_save(wb, temp_file)
## Skip empty cols
- x <- read_xlsx(file = temp_file, namedRegion = "iris", colNames = TRUE, skipEmptyCols = TRUE)
+ x <- read_xlsx(file = temp_file, named_region = "iris", col_names = TRUE, skip_empty_cols = TRUE)
expect_equal(dim(x), c(4, 1))
- x <- read_xlsx(file = temp_file, namedRegion = "iris2", colNames = TRUE, skipEmptyCols = TRUE)
+ x <- read_xlsx(file = temp_file, named_region = "iris2", col_names = TRUE, skip_empty_cols = TRUE)
expect_equal(dim(x), c(4, 2))
## Keep empty cols
- x <- read_xlsx(file = temp_file, namedRegion = "iris", colNames = TRUE, skipEmptyCols = FALSE)
+ x <- read_xlsx(file = temp_file, named_region = "iris", col_names = TRUE, skip_empty_cols = FALSE)
expect_equal(dim(x), c(4, 2))
- x <- read_xlsx(file = temp_file, namedRegion = "iris2", colNames = TRUE, skipEmptyCols = FALSE)
+ x <- read_xlsx(file = temp_file, named_region = "iris2", col_names = TRUE, skip_empty_cols = FALSE)
expect_equal(dim(x), c(4, 3))
unlink(temp_file)
@@ -314,11 +314,11 @@ test_that("Matching Substrings breaks reading named regions", {
t1$Species <- as.character(t1$Species)
t2 <- head(mtcars)
- wb$add_data(sheet = "table", x = t1, name = "t", startCol = 3, startRow = 12)
- wb$add_data(sheet = "table2", x = t2, name = "t2", startCol = 5, startRow = 24, rowNames = TRUE)
+ wb$add_data(sheet = "table", x = t1, name = "t", start_col = 3, start_row = 12)
+ wb$add_data(sheet = "table2", x = t2, name = "t2", start_col = 5, start_row = 24, row_names = TRUE)
- wb$add_data(sheet = "table", x = head(t1, 3), name = "t1", startCol = 9, startRow = 3)
- wb$add_data(sheet = "table2", x = head(t2, 3), name = "t22", startCol = 15, startRow = 12, rowNames = TRUE)
+ wb$add_data(sheet = "table", x = head(t1, 3), name = "t1", start_col = 9, start_row = 3)
+ wb$add_data(sheet = "table2", x = head(t2, 3), name = "t22", start_col = 15, start_row = 12, row_names = TRUE)
wb_save(wb, temp_file)
@@ -335,16 +335,16 @@ test_that("Matching Substrings breaks reading named regions", {
## read file named region
- expect_equal(t1, read_xlsx(file = temp_file, namedRegion = "t"), ignore_attr = TRUE)
- expect_equal(t2, read_xlsx(file = temp_file, namedRegion = "t2", rowNames = TRUE), ignore_attr = TRUE)
- expect_equal(head(t1, 3), read_xlsx(file = temp_file, namedRegion = "t1"), ignore_attr = TRUE)
- expect_equal(head(t2, 3), read_xlsx(file = temp_file, namedRegion = "t22", rowNames = TRUE), ignore_attr = TRUE)
+ expect_equal(t1, read_xlsx(file = temp_file, named_region = "t"), ignore_attr = TRUE)
+ expect_equal(t2, read_xlsx(file = temp_file, named_region = "t2", row_names = TRUE), ignore_attr = TRUE)
+ expect_equal(head(t1, 3), read_xlsx(file = temp_file, named_region = "t1"), ignore_attr = TRUE)
+ expect_equal(head(t2, 3), read_xlsx(file = temp_file, named_region = "t22", row_names = TRUE), ignore_attr = TRUE)
## read Workbook named region
- expect_equal(t1, read_xlsx(file = wb, namedRegion = "t"), ignore_attr = TRUE)
- expect_equal(t2, read_xlsx(file = wb, namedRegion = "t2", rowNames = TRUE), ignore_attr = TRUE)
- expect_equal(head(t1, 3), read_xlsx(file = wb, namedRegion = "t1"), ignore_attr = TRUE)
- expect_equal(head(t2, 3), read_xlsx(file = wb, namedRegion = "t22", rowNames = TRUE), ignore_attr = TRUE)
+ expect_equal(t1, read_xlsx(file = wb, named_region = "t"), ignore_attr = TRUE)
+ expect_equal(t2, read_xlsx(file = wb, named_region = "t2", row_names = TRUE), ignore_attr = TRUE)
+ expect_equal(head(t1, 3), read_xlsx(file = wb, named_region = "t1"), ignore_attr = TRUE)
+ expect_equal(head(t2, 3), read_xlsx(file = wb, named_region = "t22", row_names = TRUE), ignore_attr = TRUE)
unlink(temp_file)
})
@@ -354,19 +354,19 @@ test_that("Read namedRegion from specific sheet", {
filename <- system.file("extdata", "namedRegions3.xlsx", package = "openxlsx2")
- namedR <- "MyRange"
+ named_r <- "MyRange"
sheets <- wb_load(filename)$get_sheet_names()
# read the correct sheets
- expect_equal(data.frame(X1 = "S1A1", X2 = "S1B1", stringsAsFactors = FALSE), read_xlsx(filename, sheet = "Sheet1", namedRegion = namedR, rowNames = FALSE, colNames = FALSE), ignore_attr = TRUE)
- expect_equal(data.frame(X1 = "S2A1", X2 = "S2B1", stringsAsFactors = FALSE), read_xlsx(filename, sheet = which(sheets %in% "Sheet2"), namedRegion = namedR, rowNames = FALSE, colNames = FALSE), ignore_attr = TRUE)
- expect_equal(data.frame(X1 = "S3A1", X2 = "S3B1", stringsAsFactors = FALSE), read_xlsx(filename, sheet = "Sheet3", namedRegion = namedR, rowNames = FALSE, colNames = FALSE), ignore_attr = TRUE)
+ expect_equal(data.frame(X1 = "S1A1", X2 = "S1B1", stringsAsFactors = FALSE), read_xlsx(filename, sheet = "Sheet1", named_region = named_r, row_names = FALSE, col_names = FALSE), ignore_attr = TRUE)
+ expect_equal(data.frame(X1 = "S2A1", X2 = "S2B1", stringsAsFactors = FALSE), read_xlsx(filename, sheet = which(sheets %in% "Sheet2"), named_region = named_r, row_names = FALSE, col_names = FALSE), ignore_attr = TRUE)
+ expect_equal(data.frame(X1 = "S3A1", X2 = "S3B1", stringsAsFactors = FALSE), read_xlsx(filename, sheet = "Sheet3", named_region = named_r, row_names = FALSE, col_names = FALSE), ignore_attr = TRUE)
- # Warning: Workbook has no such named region. (Wrong namedRegion selected.)
- expect_error(read_xlsx(filename, sheet = "Sheet2", namedRegion = "MyRage", rowNames = FALSE, colNames = FALSE))
+ # Warning: Workbook has no such named region. (Wrong named_region selected.)
+ expect_error(read_xlsx(filename, sheet = "Sheet2", named_region = "MyRage", row_names = FALSE, col_names = FALSE))
- # Warning: Workbook has no such named region on this sheet. (Correct namedRegion, but wrong sheet selected.)
- expect_error(read_xlsx(filename, sheet = "Sheet4", namedRegion = namedR, rowNames = FALSE, colNames = FALSE))
+ # Warning: Workbook has no such named region on this sheet. (Correct named_region, but wrong sheet selected.)
+ expect_error(read_xlsx(filename, sheet = "Sheet4", named_region = named_r, row_names = FALSE, col_names = FALSE))
})
@@ -380,7 +380,7 @@ test_that("Overwrite and delete named regions", {
expect_null(wb_get_named_regions(wb))
## create region
- wb$add_data(1, iris[1:11, ], startCol = 1, startRow = 1, name = "iris")
+ wb$add_data(1, iris[1:11, ], start_col = 1, start_row = 1, name = "iris")
exp <- data.frame(
name = "iris",
value = "'Sheet 1'!A1:E12",
@@ -388,12 +388,13 @@ test_that("Overwrite and delete named regions", {
coords = "A1:E12",
id = 1L,
local = 0,
- sheet = 1L
+ sheet = 1L,
+ stringsAsFactors = FALSE
)
expect_identical(wb_get_named_regions(wb), exp)
# no overwrite
- expect_error(wb$add_data(1, iris[1:11, ], startCol = 1, startRow = 1, name = "iris"))
+ expect_error(wb$add_data(1, iris[1:11, ], start_col = 1, start_row = 1, name = "iris"))
expect_error(wb$add_named_region(1, name = "iris", dims = rowcol_to_dims(1:5, 1:2)))
@@ -409,7 +410,8 @@ test_that("Overwrite and delete named regions", {
coords = "A1:B5",
id = 1L,
local = 0,
- sheet = 1L
+ sheet = 1L,
+ stringsAsFactors = FALSE
)
# check modification
@@ -432,10 +434,10 @@ test_that("load table", {
wb <- wb_workbook()
# add a table
wb$add_worksheet("Sheet 1")
- wb$add_data_table(sheet = "Sheet 1", x = iris, tableName = "iris_tab")
+ wb$add_data_table(sheet = "Sheet 1", x = iris, table_name = "iris_tab")
# add a named region
wb$add_worksheet("Sheet 2")
- wb$add_data(sheet = "Sheet 2", x = iris, startCol = 1, startRow = 1)
+ wb$add_data(sheet = "Sheet 2", x = iris, start_col = 1, start_row = 1)
wb$add_named_region(
sheet = 2,
name = "iris",
diff --git a/tests/testthat/test-outlines.R b/tests/testthat/test-outlines.R
index db8d8f60b..8a442550e 100644
--- a/tests/testthat/test-outlines.R
+++ b/tests/testthat/test-outlines.R
@@ -44,10 +44,10 @@ test_that("group rows", {
group_rows("Sheet 1", 1:4)
got <- wb$worksheets[[1]]$sheet_data$row_attr$outlineLevel
- expect_equal(c("1", "1", "1", ""), got)
+ expect_equal(got, c("1", "1", "1", ""))
got <- wb$worksheets[[1]]$sheet_data$row_attr$r
- expect_equal(c("1", "2", "3", "4"), got)
+ expect_equal(got, c("1", "2", "3", "4"))
wb <- wb_workbook()$
add_worksheet("Sheet 1")$
@@ -55,10 +55,10 @@ test_that("group rows", {
group_rows("Sheet 1", 1:4, collapsed = TRUE)
got <- wb$worksheets[[1]]$sheet_data$row_attr$collapsed
- expect_equal(c("1", "1", "1", "1"), got)
+ expect_equal(got, c("1", "1", "1", "1"))
got <- wb$worksheets[[1]]$sheet_data$row_attr$hidden
- expect_equal(c("1", "1", "1", ""), got)
+ expect_equal(got, c("1", "1", "1", ""))
})
@@ -71,7 +71,7 @@ test_that("grouping levels", {
wb <- wb_workbook()
wb$add_worksheet("AirPass")
- wb$add_data("AirPass", t2, rowNames = TRUE)
+ wb$add_data("AirPass", t2, row_names = TRUE)
# lines used for grouping (here: species)
grp_rows <- list(
@@ -90,7 +90,7 @@ test_that("grouping levels", {
wb <- wb_workbook()
wb$add_worksheet("AirPass")
- wb$add_data("AirPass", t2, rowNames = TRUE)
+ wb$add_data("AirPass", t2, row_names = TRUE)
wb$createCols("AirPass", 13)
@@ -141,7 +141,7 @@ test_that("ungroup rows", {
wb <- wb_workbook()$
add_worksheet("Sheet 1")$
- add_data(x = cbind(rep(NA, 4)), na.strings = NULL, colNames = FALSE)$
+ add_data(x = cbind(rep(NA, 4)), na.strings = NULL, col_names = FALSE)$
group_rows("Sheet 1", 1:4)$
ungroup_rows("Sheet 1", 1:4)
@@ -214,7 +214,7 @@ test_that("with outlinePr", {
wb <- wb_workbook()
wb$add_worksheet("AirPass")
- wb$add_data("AirPass", t2, rowNames = TRUE)
+ wb$add_data("AirPass", t2, row_names = TRUE)
wb$worksheets[[1]]$sheetPr <-
xml_node_create(
@@ -255,7 +255,8 @@ test_that("hierarchical grouping works", {
Var2 = c("B", "B", "B", "C", "C", "C", ""),
Var3 = c("BA", "BB", "", "CA", "CB", "", ""),
Var4 = c("BA", "BB", "", "CA", "CB", "", ""),
- Result = c(1, 2, 3, 4, 5, 9, 12)
+ Result = c(1, 2, 3, 4, 5, 9, 12),
+ stringsAsFactors = FALSE
)
wb <- wb_workbook()$
@@ -278,9 +279,9 @@ test_that("hierarchical grouping works", {
)
wb$group_cols(cols = grp_cols)
- exp <- c("", "3", "3", "1", "3", "3", "1", "")
got <- wb$worksheets[[1]]$sheet_data$row_attr$outlineLevel
- expect_equal(exp, got)
+ exp <- c("", "3", "3", "1", "3", "3", "1", "")
+ expect_equal(got, exp)
exp <- c(
"",
@@ -289,6 +290,5 @@ test_that("hierarchical grouping works", {
"",
""
)
- got <- wb$worksheets[[1]]$cols_attr
- expect_equal(exp, got)
+ expect_equal(wb$worksheets[[1]]$cols_attr, exp)
})
diff --git a/tests/testthat/test-page_setup.R b/tests/testthat/test-page_setup.R
index 4a7db9a70..4a02b5e00 100644
--- a/tests/testthat/test-page_setup.R
+++ b/tests/testthat/test-page_setup.R
@@ -5,16 +5,16 @@ test_that("Page setup", {
wb$page_setup(
sheet = "s1", orientation = "landscape", scale = 100, left = 0.1,
- right = 0.1, top = .75, bottom = .75, header = 0.1, footer = 0.1,
- fitToWidth = TRUE, fitToHeight = TRUE, paperSize = 1,
- summaryRow = "below", summaryCol = "right"
+ right = 0.1, top = 0.75, bottom = 0.75, header = 0.1, footer = 0.1,
+ fit_to_width = TRUE, fit_to_height = TRUE, paper_size = 1,
+ summary_row = "below", summary_col = "right"
)
wb$page_setup(
sheet = 2, orientation = "landscape", scale = 100, left = 0.1,
- right = 0.1, top = .75, bottom = .75, header = 0.1, footer = 0.1,
- fitToWidth = TRUE, fitToHeight = TRUE, paperSize = 1,
- summaryRow = "below", summaryCol = "right"
+ right = 0.1, top = 0.75, bottom = 0.75, header = 0.1, footer = 0.1,
+ fit_to_width = TRUE, fit_to_height = TRUE, paper_size = 1,
+ summary_row = "below", summary_col = "right"
)
expect_equal(wb$worksheets[[1]]$pageSetup, wb$worksheets[[2]]$pageSetup)
@@ -49,8 +49,8 @@ test_that("page_breaks", {
)
cbrk <- ""
- expect_equal(rbrk, wb$worksheets[[1]]$rowBreaks)
- expect_equal(cbrk, wb$worksheets[[1]]$colBreaks)
+ expect_equal(wb$worksheets[[1]]$rowBreaks, rbrk)
+ expect_equal(wb$worksheets[[1]]$colBreaks, cbrk)
wb$save(temp)
wb2 <- wb_load(temp)
diff --git a/tests/testthat/test-protect-workbook.R b/tests/testthat/test-protect-workbook.R
index 32d3d8f71..6b9672bdb 100644
--- a/tests/testthat/test-protect-workbook.R
+++ b/tests/testthat/test-protect-workbook.R
@@ -6,13 +6,13 @@ test_that("Protect Workbook", {
wb$protect(password = "abcdefghij")
- expect_true(wb$workbook$workbookProtection == "")
+ expect_equal(wb$workbook$workbookProtection, "")
# this creates a corrupted workbook:
# 1) this nulls the reference
wb$protect(protect = FALSE, password = "abcdefghij", lockStructure = TRUE, lockWindows = TRUE)
- expect_true(is.null(wb$workbook$workbookProtection))
+ expect_null(wb$workbook$workbookProtection)
# 2) this creates the reference, but at the wrong position (at the end, not at 6)
wb$protect(password = "abcdefghij", lockStructure = TRUE)
diff --git a/tests/testthat/test-pugi_cpp.R b/tests/testthat/test-pugi_cpp.R
index 5e106d6cc..1bddcd04d 100644
--- a/tests/testthat/test-pugi_cpp.R
+++ b/tests/testthat/test-pugi_cpp.R
@@ -73,15 +73,15 @@ test_that("xml_attr", {
xml_str <- ""
xml <- read_xml(xml_str)
- expect_equal(exp, getXMLXPtr1attr(xml, "a"))
+ expect_equal(getXMLXPtr1attr(xml, "a"), exp)
xml_str <- ""
xml <- read_xml(xml_str)
- expect_equal(exp, getXMLXPtr2attr(xml, "b", "a"))
+ expect_equal(getXMLXPtr2attr(xml, "b", "a"), exp)
xml_str <- ""
xml <- read_xml(xml_str)
- expect_equal(exp, getXMLXPtr3attr(xml, "c", "b", "a"))
+ expect_equal(getXMLXPtr3attr(xml, "c", "b", "a"), exp)
})
@@ -90,26 +90,26 @@ test_that("xml_append_child", {
xml_node <- read_xml("")
xml_child <- read_xml("&")
exp <- "&"
- expect_equal(exp, xml_append_child1(xml_node, xml_child, pointer = FALSE))
+ expect_equal(xml_append_child1(xml_node, xml_child, pointer = FALSE), exp)
# xml_node sets the flags for both
xml_node <- read_xml("", escapes = TRUE)
xml_child <- read_xml("&")
exp <- "&"
- expect_equal(exp, xml_append_child1(xml_node, xml_child, pointer = FALSE))
+ expect_equal(xml_append_child1(xml_node, xml_child, pointer = FALSE), exp)
xml_node <- ""
xml_child <- read_xml("")
xml_node <- xml_append_child1(read_xml(xml_node), xml_child, pointer = FALSE)
- expect_equal("", xml_node)
+ expect_equal(xml_node, "")
xml_node <- xml_append_child2(read_xml(xml_node), xml_child, level1 = "b", pointer = FALSE)
- expect_equal("", xml_node)
+ expect_equal(xml_node, "")
xml_node <- xml_append_child3(read_xml(xml_node), read_xml(""), level1 = "b", level2 = "c", pointer = FALSE)
- expect_equal("", xml_node)
+ expect_equal(xml_node, "")
# check that escapes does not throw a warning
@@ -117,13 +117,13 @@ test_that("xml_append_child", {
xml_child <- read_xml("a&b", escapes = FALSE)
xml_node <- xml_append_child1(read_xml(xml_node, escapes = TRUE), xml_child, pointer = FALSE)
- expect_equal("a&b", xml_node)
+ expect_equal(xml_node, "a&b")
xml_node <- xml_append_child2(read_xml(xml_node, escapes = TRUE), xml_child, level1 = "b", pointer = FALSE)
- expect_equal("a&ba&b", xml_node)
+ expect_equal(xml_node, "a&ba&b")
xml_node <- xml_append_child3(read_xml(xml_node, escapes = TRUE), read_xml(""), level1 = "b", level2 = "c", pointer = FALSE)
- expect_equal("a&ba&b", xml_node)
+ expect_equal(xml_node, "a&ba&b")
# check that pointer is valid
expect_true(inherits(xml_append_child1(read_xml(xml_node), xml_child, pointer = TRUE), "pugi_xml"))
@@ -176,9 +176,9 @@ test_that("is_xml", {
test_that("getXMLPtr1con", {
xml <- ""
- exp <- c("", "", "")
got <- getXMLPtr1con(read_xml(xml))
- expect_equal(exp, got)
+ exp <- c("", "", "")
+ expect_equal(got, exp)
})
diff --git a/tests/testthat/test-pugixml.R b/tests/testthat/test-pugixml.R
index e05690594..c38f9a7d0 100644
--- a/tests/testthat/test-pugixml.R
+++ b/tests/testthat/test-pugixml.R
@@ -92,39 +92,37 @@ test_that("xml_node", {
xml <- ""
x <- read_xml(xml, pointer = FALSE)
- expect_equal("a", xml_node_name(x))
- expect_equal(xml, xml_node(x))
- expect_equal(xml, xml_node(x, "a"))
+ expect_equal(xml_node_name(x), "a")
+ expect_equal(xml_node(x), xml)
+ expect_equal(xml_node(x, "a"), xml)
expect_error(xml_node(x, 1))
- exp <- ""
- expect_equal(exp, xml_node(x, "a", "b"))
+ expect_equal(xml_node(x, "a", "b"), "")
- expect_equal(xml, xml_node("", "a"))
+ expect_equal(xml_node("", "a"), xml)
- exp <- ""
- expect_equal(exp, xml_node("", "a", "b"))
+ expect_equal(xml_node("", "a", "b"), "")
xml_str <- ""
xml <- read_xml(xml_str)
- expect_equal("b", xml_node_name(xml_str, "a"))
- expect_equal("c", xml_node_name(xml_str, "a", "b"))
- expect_equal("b", xml_node_name(xml, "a"))
- expect_equal("c", xml_node_name(xml, "a", "b"))
+ expect_equal(xml_node_name(xml_str, "a"), "b")
+ expect_equal(xml_node_name(xml_str, "a", "b"), "c")
+ expect_equal(xml_node_name(xml, "a"), "b")
+ expect_equal(xml_node_name(xml, "a", "b"), "c")
exp <- xml_str
- expect_equal(exp, xml_node(xml, "a"))
+ expect_equal(xml_node(xml, "a"), exp)
exp <- ""
- expect_equal(exp, xml_node(xml, "a", "b"))
+ expect_equal(xml_node(xml, "a", "b"), exp)
exp <- ""
- expect_equal(exp, xml_node(xml, "a", "b", "c"))
+ expect_equal(xml_node(xml, "a", "b", "c"), exp)
# bit cheating, this test returns the same, but not the actual feature of "*"
- expect_equal(exp, xml_node(xml, "a", "*", "c"))
+ expect_equal(xml_node(xml, "a", "*", "c"), exp)
})
@@ -132,34 +130,34 @@ test_that("xml_attr", {
x <- read_xml("1")
exp <- list(c(a = "1", b = "2"))
- expect_equal(exp, xml_attr(x, "a"))
+ expect_equal(xml_attr(x, "a"), exp)
expect_error(xml_attr(x, 1))
x <- read_xml("2")
exp <- list(c(r = "1"))
- expect_equal(exp, xml_attr(x, "a", "b"))
+ expect_equal(xml_attr(x, "a", "b"), exp)
x <- read_xml("1")
exp <- list(c(a = "1", b = "2"))
- expect_equal(exp, xml_attr(x, "a"))
+ expect_equal(xml_attr(x, "a"), exp)
x <- read_xml("")
exp <- list(c(a = "1", b = "2"))
- expect_equal(exp, xml_attr(x, "b", "a"))
+ expect_equal(xml_attr(x, "b", "a"), exp)
exp <- list(c(a = "1", b = "2"))
- expect_equal(exp, xml_attr("1", "a"))
+ expect_equal(xml_attr("1", "a"), exp)
exp <- list(c(r = "1"))
- expect_equal(exp, xml_attr("2", "a", "b"))
+ expect_equal(xml_attr("2", "a", "b"), exp)
exp <- list(c(a = "1", b = "2"))
- expect_equal(exp, xml_attr("1", "a"))
+ expect_equal(xml_attr("1", "a"), exp)
exp <- list(c(a = "1", b = "2"))
- expect_equal(exp, xml_attr("", "b", "a"))
+ expect_equal(xml_attr("", "b", "a"), exp)
@@ -167,47 +165,44 @@ test_that("xml_attr", {
xml_str <- ""
xml <- read_xml(xml_str)
- expect_equal(exp, xml_attr(xml, "a"))
+ expect_equal(xml_attr(xml, "a"), exp)
xml_str <- ""
xml <- read_xml(xml_str)
- expect_equal(exp, xml_attr(xml, "b", "a"))
+ expect_equal(xml_attr(xml, "b", "a"), exp)
xml_str <- ""
xml <- read_xml(xml_str)
- expect_equal(exp, xml_attr(xml, "c", "b", "a"))
+ expect_equal(xml_attr(xml, "c", "b", "a"), exp)
})
test_that("xml_value", {
x <- read_xml("1")
- exp <- "1"
- expect_equal(exp, xml_value(x, "a"))
+ expect_equal(xml_value(x, "a"), "1")
expect_error(xml_value(x, 1))
x <- read_xml("2")
- exp <- "2"
- expect_equal(exp, xml_value(x, "a", "b"))
+ expect_equal(xml_value(x, "a", "b"), "2")
x <- read_xml("23")
- exp <- c("2", "3")
- expect_equal(exp, xml_value(x, "a", "b"))
+ expect_equal(xml_value(x, "a", "b"), c("2", "3"))
exp <- "1"
xml_str <- "1"
xml <- read_xml(xml_str)
- expect_equal(exp, xml_value(xml, "a"))
+ expect_equal(xml_value(xml, "a"), "1")
xml_str <- "1"
xml <- read_xml(xml_str)
- expect_equal(exp, xml_value(xml, "a", "b"))
+ expect_equal(xml_value(xml, "a", "b"), "1")
xml_str <- "1"
xml <- read_xml(xml_str)
- expect_equal(exp, xml_value(xml, "a", "b", "c"))
+ expect_equal(xml_value(xml, "a", "b", "c"), "1")
})
@@ -239,7 +234,7 @@ test_that("xml_add_child", {
exp <- ""
- expect_equal(exp, xml_add_child(xml_node, xml_child))
+ expect_equal(xml_add_child(xml_node, xml_child), exp)
expect_error(xml_add_child(xml_node))
expect_error(xml_add_child(xml_child = xml_child))
@@ -248,13 +243,13 @@ test_that("xml_add_child", {
xml_child <- ""
xml_node <- xml_add_child(xml_node, xml_child)
- expect_equal("", xml_node)
+ expect_equal(xml_node, "")
xml_node <- xml_add_child(xml_node, xml_child, level = c("b"))
- expect_equal("", xml_node)
+ expect_equal(xml_node, "")
xml_node <- xml_add_child(xml_node, "", level = c("b", "c"))
- expect_equal("", xml_node)
+ expect_equal(xml_node, "")
})
@@ -262,44 +257,48 @@ test_that("xml_add_child", {
test_that("xml_rm_child", {
- xml_node <- "12"
- xml_child <- "c"
-
- expect_equal("", xml_rm_child(xml_node, xml_child, which = 0))
- expect_equal("2", xml_rm_child(xml_node, xml_child, which = 1))
- expect_equal("1", xml_rm_child(xml_node, xml_child, which = 2))
- expect_equal("12", xml_rm_child(xml_node, xml_child, which = 3))
+ rm_child <- function(which) {
+ xml_rm_child(
+ xml_node = "12",
+ xml_child = "c",
+ which = which
+ )
+ }
+ expect_equal(rm_child(which = 0), "")
+ expect_equal(rm_child(which = 1), "2")
+ expect_equal(rm_child(which = 2), "1")
+ expect_equal(rm_child(which = 3), "12")
xml_node <- "12"
xml_child <- "c"
- exp <- "2"
got <- xml_rm_child(xml_node, "b", which = 1)
- expect_equal(exp, got)
+ exp <- "2"
+ expect_equal(got, exp)
xml_node <- exp
- exp <- "2"
got <- xml_rm_child(xml_node, xml_child, "b", which = 1)
- expect_equal(exp, got)
+ exp <- "2"
+ expect_equal(got, exp)
- exp <- "2"
got <- xml_rm_child(xml_node, xml_child, level = "b", which = 2)
- expect_equal(exp, got)
+ exp <- "2"
+ expect_equal(got, exp)
- exp <- "2"
got <- xml_rm_child(xml_node, xml_child, "b", which = 0)
- expect_equal(exp, got)
+ exp <- "2"
+ expect_equal(got, exp)
xml_node <- "123"
- exp <- "13"
got <- xml_rm_child(xml_node, xml_child, level = c("a", "b"), which = 2)
- expect_equal(exp, got)
+ exp <- "13"
+ expect_equal(got, exp)
- exp <- ""
got <- xml_rm_child(xml_node, xml_child, level = c("a", "b"), which = 0)
- expect_equal(exp, got)
+ exp <- ""
+ expect_equal(got, exp)
})
diff --git a/tests/testthat/test-read_from_created_wb.R b/tests/testthat/test-read_from_created_wb.R
index 66a027b9f..07bf8fa88 100644
--- a/tests/testthat/test-read_from_created_wb.R
+++ b/tests/testthat/test-read_from_created_wb.R
@@ -9,28 +9,28 @@ test_that("Reading from new workbook", {
## colNames = TRUE, rowNames = TRUE
- wb$add_data(sheet = 1, x = mtcars, colNames = TRUE, rowNames = TRUE, startRow = 10, startCol = 5)
- x <- read_xlsx(wb, 1, colNames = TRUE, rowNames = TRUE)
+ wb$add_data(sheet = 1, x = mtcars, col_names = TRUE, row_names = TRUE, start_row = 10, start_col = 5)
+ x <- read_xlsx(wb, 1, col_names = TRUE, row_names = TRUE)
expect_equal(object = mtcars, expected = x, ignore_attr = TRUE)
## colNames = TRUE, rowNames = FALSE
- wb$add_data(sheet = 2, x = mtcars, colNames = TRUE, rowNames = FALSE, startRow = 10, startCol = 5)
- x <- read_xlsx(wb, sheet = 2, colNames = TRUE, rowNames = FALSE)
+ wb$add_data(sheet = 2, x = mtcars, col_names = TRUE, row_names = FALSE, start_row = 10, start_col = 5)
+ x <- read_xlsx(wb, sheet = 2, col_names = TRUE, row_names = FALSE)
expect_equal(object = mtcars, expected = x, ignore_attr = TRUE)
expect_equal(object = colnames(mtcars), expected = colnames(x), ignore_attr = TRUE)
## colNames = FALSE, rowNames = TRUE
- wb$add_data(sheet = 3, x = mtcars, colNames = FALSE, rowNames = TRUE, startRow = 2, startCol = 2)
- x <- read_xlsx(wb, sheet = 3, colNames = FALSE, rowNames = TRUE)
+ wb$add_data(sheet = 3, x = mtcars, col_names = FALSE, row_names = TRUE, start_row = 2, start_col = 2)
+ x <- read_xlsx(wb, sheet = 3, col_names = FALSE, row_names = TRUE)
expect_equal(object = mtcars, expected = x, ignore_attr = TRUE)
- expect_equal(object = rownames(mtcars), expected = rownames(x))
+ expect_equal(object = rownames(x), expected = rownames(mtcars))
## colNames = FALSE, rowNames = FALSE
- wb$add_data(sheet = 4, x = mtcars, colNames = FALSE, rowNames = FALSE, startRow = 12, startCol = 1)
- x <- read_xlsx(wb, sheet = 4, colNames = FALSE, rowNames = FALSE)
- expect_equal(object = mtcars, expected = x, ignore_attr = TRUE)
+ wb$add_data(sheet = 4, x = mtcars, col_names = FALSE, row_names = FALSE, start_row = 12, start_col = 1)
+ x <- read_xlsx(wb, sheet = 4, col_names = FALSE, row_names = FALSE)
+ expect_equal(object = x, expected = mtcars, ignore_attr = TRUE)
expect_equal(object = getwd(), curr_wd)
rm(wb)
@@ -91,36 +91,36 @@ test_that("dims != rows & cols", {
add_worksheet("sheet1")$
add_data(1, data.frame("A" = 1))
- got1 <- wb_to_df(wb, dims = "A2:D5", colNames = FALSE)
- got2 <- wb_to_df(wb, rows = 2:5, cols = 1:4, colNames = FALSE)
+ got1 <- wb_to_df(wb, dims = "A2:D5", col_names = FALSE)
+ got2 <- wb_to_df(wb, rows = 2:5, cols = 1:4, col_names = FALSE)
expect_equal(got1, got2)
- got3 <- wb_to_df(wb, rows = c(2:3, 5:6), cols = c(1, 3:5), colNames = FALSE)
- expect_equal(c(4, 4), dim(got3))
- expect_equal(c("A", "C", "D", "E"), colnames(got3))
- expect_equal(c("2", "3", "5", "6"), rownames(got3))
+ got3 <- wb_to_df(wb, rows = c(2:3, 5:6), cols = c(1, 3:5), col_names = FALSE)
+ expect_equal(dim(got3), c(4L, 4L))
+ expect_equal(colnames(got3), c("A", "C", "D", "E"))
+ expect_equal(rownames(got3), c("2", "3", "5", "6"))
- got4 <- wb_to_df(wb, rows = 1:5, colNames = FALSE)
- expect_equal(c(5, 1), dim(got4))
+ got4 <- wb_to_df(wb, rows = 1:5, col_names = FALSE)
+ expect_equal(dim(got4), c(5L, 1L))
- got5 <- wb_to_df(wb, cols = 1:5, colNames = FALSE)
- expect_equal(c(2, 5), dim(got5))
+ got5 <- wb_to_df(wb, cols = 1:5, col_names = FALSE)
+ expect_equal(dim(got5), c(2, 5))
- got6 <- wb_to_df(wb, startRow = 4, cols = 1:4, colNames = FALSE)
+ got6 <- wb_to_df(wb, start_row = 4, cols = 1:4, col_names = FALSE)
expect_true(all(is.na(got6)))
- expect_equal("4", rownames(got6))
+ expect_equal(rownames(got6), "4")
})
test_that("read startCol", {
- wb <- wb_workbook()$add_worksheet()$add_data(x = cars, startCol = "E")
+ wb <- wb_workbook()$add_worksheet()$add_data(x = cars, start_col = "E")
- got <- wb_to_df(wb, startCol = 1, colNames = FALSE)
- expect_equal(LETTERS[1:6], names(got))
+ got <- wb_to_df(wb, start_col = 1, col_names = FALSE)
+ expect_equal(names(got), LETTERS[1:6])
- got <- wb_to_df(wb, startCol = "F", colNames = FALSE)
- expect_equal(LETTERS[6], names(got))
+ got <- wb_to_df(wb, start_col = "F", col_names = FALSE)
+ expect_equal(names(got), LETTERS[6])
})
@@ -132,7 +132,7 @@ test_that("reading with multiple sections in freezePane works", {
expect_silent(wb <- wb_load(temp))
})
-test_that("skipEmtpyCols keeps empty named columns", {
+test_that("skipEmptyCols keeps empty named columns", {
## initialize empty cells
na_mat <- matrix(NA, nrow = 22, ncol = 7)
@@ -145,10 +145,10 @@ test_that("skipEmtpyCols keeps empty named columns", {
## create the workbook
wb <- wb_workbook()$
add_worksheet()$
- add_data(x = na_mat, colNames = FALSE)$
+ add_data(x = na_mat, col_names = FALSE)$
add_data(x = dat)
- got <- wb_to_df(wb, skipEmptyCols = TRUE)
+ got <- wb_to_df(wb, skip_empty_cols = TRUE)
expect_equal(dat, got, ignore_attr = TRUE)
})
diff --git a/tests/testthat/test-read_sources.R b/tests/testthat/test-read_sources.R
index fba171ac8..1b0ad9213 100644
--- a/tests/testthat/test-read_sources.R
+++ b/tests/testthat/test-read_sources.R
@@ -56,14 +56,14 @@ test_that("read html source without r attribute on cell", {
# original from https://www.atih.sante.fr/sites/default/files/public/content/3968/fichier_complementaire_ccam_descriptive_a_usage_pmsi_2021_v2.xlsx
wb <- wb_load(testfile_path("fichier_complementaire_ccam_descriptive_a_usage_pmsi_2021_v2.xlsx"))
- expect_equal(c(46, 1), dim(wb_to_df(wb, sheet = 1)))
- expect_equal(c(31564, 52), dim(wb_to_df(wb, sheet = 2)))
- expect_equal("PRÉSENTATION DU DOCUMENT", names(wb_to_df(wb, sheet = 1)))
+ expect_equal(dim(wb_to_df(wb, sheet = 1)), c(46L, 1L))
+ expect_equal(dim(wb_to_df(wb, sheet = 2)), c(31564L, 52L))
+ expect_equal(names(wb_to_df(wb, sheet = 1)), "PRÉSENTATION DU DOCUMENT")
# This file has a few cells with row names, the majority has none. check that
# we did not create duplicates while loading
- expect_true(!any(duplicated(wb$worksheets[[1]]$sheet_data$cc)))
- expect_true(!any(duplicated(wb$worksheets[[2]]$sheet_data$cc)))
+ expect_false(any(duplicated(wb$worksheets[[1]]$sheet_data$cc)))
+ expect_false(any(duplicated(wb$worksheets[[2]]$sheet_data$cc)))
})
@@ -81,8 +81,8 @@ test_that("read vml from sheet two works as expected", {
# test
expect_silent(wb <- wb_load(testfile_path("vml_numbering.xlsx")))
- expect_equal(1L, length(wb$vml))
- expect_equal(1L, length(wb$vml_rels))
+ expect_equal(length(wb$vml), 1L)
+ expect_equal(length(wb$vml_rels), 1L)
})
@@ -99,7 +99,7 @@ test_that("encoding", {
row.names = 2L, class = "data.frame"),
types = c(A = 0, B = 0))
- expect_equal(exp, wb_to_df(wb, keep_attributes = TRUE))
+ expect_equal(wb_to_df(wb, keep_attributes = TRUE), exp)
fl <- testfile_path("eurosymbol.xlsx")
wb <- wb_load(fl)
@@ -125,7 +125,7 @@ test_that("encoding", {
exp <- "\n äöüß\n ÄÖÜ\n €\n"
got <- paste(capture.output(
read_xml(system.file("extdata", "unicode.xml", package = "openxlsx2"))
- ), collapse = "\n")
+ ), collapse = "\n")
expect_equal(exp, got)
exp <- "äöüßÄÖÜ€"
@@ -186,8 +186,8 @@ test_that("reading charts", {
wb$remove_worksheet(rmsheet)
expect_false(any(grepl("drawing21.xml", unlist(wb$worksheets_rels))))
- expect_equal("", wb$drawings[[21]])
- expect_equal("", wb$drawings_rels[[21]])
+ expect_equal(wb$drawings[[21]], "")
+ expect_equal(wb$drawings_rels[[21]], "")
})
@@ -228,13 +228,13 @@ test_that("load file with connection", {
wb <- wb_load(testfile_path("connection.xlsx"))
- expect_true(!is.null(wb$customXml))
- expect_equal(3, length(wb$customXml))
+ expect_false(is.null(wb$customXml))
+ expect_equal(length(wb$customXml), 3)
wb$save(temp)
wb <- wb_load(temp)
- expect_equal(3, length(wb$customXml))
+ expect_equal(length(wb$customXml), 3)
expect_true(grepl("customXml/_rels/item1.xml.rels", wb$customXml[1]))
expect_true(grepl("customXml/item1.xml", wb$customXml[2]))
@@ -329,8 +329,8 @@ test_that("reading multiple slicers on a pivot table works", {
wb <- wb_load(testfile_path("gh_issue_504.xlsx"))
- expect_equal(1L, length(wb$slicers))
- expect_equal(2L, length(wb$slicerCaches))
+ expect_equal(length(wb$slicers), 1L)
+ expect_equal(length(wb$slicerCaches), 2L)
exp <- c(
"",
diff --git a/tests/testthat/test-remove_worksheets.R b/tests/testthat/test-remove_worksheets.R
index cd9c27439..4d251cf9d 100644
--- a/tests/testthat/test-remove_worksheets.R
+++ b/tests/testthat/test-remove_worksheets.R
@@ -2,7 +2,7 @@ test_that("Deleting worksheets", {
tempFile <- temp_xlsx()
genWS <- function(wb, sheetName) {
wb$add_worksheet(sheetName)
- wb$add_data_table(sheetName, data.frame("X" = sprintf("This is sheet: %s", sheetName)), colNames = TRUE)
+ wb$add_data_table(sheetName, data.frame("X" = sprintf("This is sheet: %s", sheetName)), col_names = TRUE)
}
wb <- wb_workbook()
@@ -29,25 +29,25 @@ test_that("Deleting worksheets", {
wb <- wb_load(tempFile)
expect_equal(names(wb$get_sheet_names()), c("Sheet 3", "Sheet 1", "Sheet 2"))
- wb$add_data(sheet = "Sheet 2", x = iris[1:10, 1:4], startRow = 5)
- test <- read_xlsx(wb, "Sheet 2", startRow = 5)
+ wb$add_data(sheet = "Sheet 2", x = iris[1:10, 1:4], start_row = 5)
+ test <- read_xlsx(wb, "Sheet 2", start_row = 5)
rownames(test) <- seq_len(nrow(test))
attr(test, "tt") <- NULL
attr(test, "types") <- NULL
expect_equal(iris[1:10, 1:4], test)
- wb$add_data(sheet = 1, x = iris[1:20, 1:4], startRow = 5)
- test <- read_xlsx(wb, "Sheet 3", startRow = 5)
+ wb$add_data(sheet = 1, x = iris[1:20, 1:4], start_row = 5)
+ test <- read_xlsx(wb, "Sheet 3", start_row = 5)
rownames(test) <- seq_len(nrow(test))
attr(test, "tt") <- NULL
attr(test, "types") <- NULL
expect_equal(iris[1:20, 1:4], test)
wb$remove_worksheet(sheet = 1)
- expect_equal("This is sheet: Sheet 1", read_xlsx(wb, 1, startRow = 1)[[1]])
+ expect_equal(read_xlsx(wb, 1, start_row = 1)[[1]], "This is sheet: Sheet 1")
wb$remove_worksheet(sheet = 2)
- expect_equal("This is sheet: Sheet 1", read_xlsx(wb, 1, startRow = 1)[[1]])
+ expect_equal(read_xlsx(wb, 1, start_row = 1)[[1]], "This is sheet: Sheet 1")
wb$remove_worksheet(sheet = 1)
expect_equal(names(wb$get_sheet_names()), character(0))
@@ -89,9 +89,7 @@ test_that("removing leading chartsheets works", {
remove_worksheet(1)$
add_worksheet()
- exp <- c("Sheet 2", "Sheet 3")
- got <- wb$sheet_names
- expect_equal(exp, got)
+ expect_equal(wb$sheet_names, c("Sheet 2", "Sheet 3"))
###
skip_if_not_installed("mschart")
@@ -125,9 +123,9 @@ test_that("removing leading chartsheets works", {
dir.create(tmp_dir)
unzip(tmp, exdir = tmp_dir)
- exp <- c("sheet1.xml", "sheet2.xml")
got <- dir(paste0(tmp_dir, "/xl/worksheets"), pattern = "*.xml")
- expect_equal(exp, got)
+ exp <- c("sheet1.xml", "sheet2.xml")
+ expect_equal(got, exp)
unlink(tmp_dir, recursive = TRUE)
@@ -140,13 +138,13 @@ test_that("bookViews activeTab attribute is updated", {
add_worksheet()
wb$set_active_sheet(2)
- exp <- ""
got <- wb$workbook$bookViews
- expect_equal(exp, got)
+ exp <- ""
+ expect_equal(got, exp)
wb$remove_worksheet(1)
- exp <- ""
got <- wb$workbook$bookViews
- expect_equal(exp, got)
+ exp <- ""
+ expect_equal(got, exp)
})
diff --git a/tests/testthat/test-save.R b/tests/testthat/test-save.R
index e24807a58..f63a591a8 100644
--- a/tests/testthat/test-save.R
+++ b/tests/testthat/test-save.R
@@ -37,7 +37,7 @@ test_that("creating hyperlinks", {
# warning: col and row provided, but not required
expect_warning(
linkString <- create_hyperlink(col = 1, row = 4,
- text = "test.png", file = img))
+ text = "test.png", file = img))
linkString2 <- create_hyperlink(text = "test.png", file = img)
diff --git a/tests/testthat/test-strings_xml.R b/tests/testthat/test-strings_xml.R
index f7a4c9ede..4aa7adf24 100644
--- a/tests/testthat/test-strings_xml.R
+++ b/tests/testthat/test-strings_xml.R
@@ -2,52 +2,51 @@ test_that("strings_xml", {
# some sst string
si <- "foobar"
-
expect_equal(
- c("foo", "bar"),
- xml_si_to_txt(read_xml(si))
+ xml_si_to_txt(read_xml(si)),
+ c("foo", "bar")
)
txt <- "foo"
expect_equal(
- "foo",
- txt_to_si(txt, raw = TRUE, skip_control = FALSE)
+ txt_to_si(txt, raw = TRUE, skip_control = FALSE),
+ "foo"
)
expect_equal(
- "\n foo\n\n",
- txt_to_si(txt, raw = FALSE, skip_control = FALSE)
+ txt_to_si(txt, raw = FALSE, skip_control = FALSE),
+ "\n foo\n\n"
)
txt <- "foo "
expect_equal(
- "foo ",
- txt_to_si(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE)
+ txt_to_si(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE),
+ "foo "
)
expect_equal(
- "\n foo \n\n",
- txt_to_si(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE)
+ txt_to_si(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE),
+ "\n foo \n\n"
)
txt <- "foo&bar"
expect_equal(
- "foo&bar",
- txt_to_si(txt, no_escapes = FALSE, skip_control = FALSE)
+ txt_to_si(txt, no_escapes = FALSE, skip_control = FALSE),
+ "foo&bar"
)
expect_equal(
- "foo&bar",
- txt_to_si(txt, no_escapes = TRUE, skip_control = FALSE)
+ txt_to_si(txt, no_escapes = TRUE, skip_control = FALSE),
+ "foo&bar"
)
txt <- "foo'abcd\037'"
expect_equal(
- "foo'abcd'",
- txt_to_si(txt, raw = TRUE, no_escapes = FALSE, skip_control = TRUE)
+ txt_to_si(txt, raw = TRUE, no_escapes = FALSE, skip_control = TRUE),
+ "foo'abcd'"
)
is <- c("foo", "bar")
expect_equal(
- c("foo", "bar"),
- is_to_txt(is)
+ is_to_txt(is),
+ c("foo", "bar")
)
is <- "foo"
@@ -56,38 +55,38 @@ test_that("strings_xml", {
txt <- "foo"
expect_equal(
- "foo",
- txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE)
+ txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE),
+ "foo"
)
expect_equal(
- "\n foo\n\n",
- txt_to_is(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE)
+ txt_to_is(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE),
+ "\n foo\n\n"
)
txt <- "foo "
expect_equal(
- "foo ",
- txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE)
+ txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE),
+ "foo "
)
expect_equal(
- "\n foo \n\n",
- txt_to_is(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE)
+ txt_to_is(txt, raw = FALSE, no_escapes = FALSE, skip_control = FALSE),
+ "\n foo \n\n"
)
txt <- "foo&bar"
expect_equal(
- "foo&bar",
- txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE)
+ txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = FALSE),
+ "foo&bar"
)
expect_equal(
- "foo&bar",
- txt_to_is(txt, raw = TRUE, no_escapes = TRUE, skip_control = FALSE)
+ txt_to_is(txt, raw = TRUE, no_escapes = TRUE, skip_control = FALSE),
+ "foo&bar"
)
txt <- "foo'abcd\037'"
expect_equal(
- "foo'abcd'",
- txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = TRUE)
+ txt_to_is(txt, raw = TRUE, no_escapes = FALSE, skip_control = TRUE),
+ "foo'abcd'"
)
amp <- temp_xlsx()
@@ -96,49 +95,47 @@ test_that("strings_xml", {
add_data(dims = "A1", x = "A & B")$
save(amp)
- exp <- "A & B"
- got <- wb_to_df(amp, colNames = FALSE)[1, 1]
- expect_equal(exp, got)
+ got <- wb_to_df(amp, col_names = FALSE)[1, 1]
+ expect_equal(got, "A & B")
# a couple of saves and loads later ...
- exp <- "A & B"
got <- wb$worksheets[[1]]$sheet_data$cc$is
- expect_equal(exp, got)
+ expect_equal(got, "A & B")
wb <- wb_load(amp)
got <- wb$worksheets[[1]]$sheet_data$cc$is
- expect_equal(exp, got)
+ expect_equal(got, "A & B")
wb$save(amp)
wb <- wb_load(amp)
got <- wb$worksheets[[1]]$sheet_data$cc$is
- expect_equal(exp, got)
+ expect_equal(got, "A & B")
- exp <- "foo <em>bar</em>"
got <- txt_to_is('foo bar')
- expect_equal(exp, got)
+ exp <- "foo <em>bar</em>"
+ expect_equal(got, exp)
# exception to the rule: it is not possible to write characters starting with "" or """
+ got <- txt_to_is("foo")
exp <- "foo"
- got <- txt_to_is('foo')
- expect_equal(exp, got)
+ expect_equal(got, exp)
- exp <- "<r>foo</r>"
got <- txt_to_is(fmt_txt('foo'))
- expect_equal(exp, got)
+ exp <- "<r>foo</r>"
+ expect_equal(got, exp)
- exp <- "<red>foo</red>"
got <- txt_to_is('foo')
- expect_equal(exp, got)
+ exp <- "<red>foo</red>"
+ expect_equal(got, exp)
- exp <- "foo</r>"
got <- txt_to_is('foo')
- expect_equal(exp, got)
+ exp <- "foo</r>"
+ expect_equal(got, exp)
- exp <- " <r>foo</r>"
got <- txt_to_is(' foo')
- expect_equal(exp, got)
+ exp <- " <r>foo</r>"
+ expect_equal(got, exp)
})
diff --git a/tests/testthat/test-tables.R b/tests/testthat/test-tables.R
index 6c7b863fb..e41fbc0f0 100644
--- a/tests/testthat/test-tables.R
+++ b/tests/testthat/test-tables.R
@@ -7,42 +7,42 @@ test_that("write_datatable over tables", {
wb <- wb_add_worksheet(wb_workbook(), "Sheet1")
## table covers rows 4->10 and cols 4->8
- wb$add_data_table(sheet = 1, x = head(iris), startCol = 4, startRow = 4)
+ wb$add_data_table(sheet = 1, x = head(iris), start_col = 4, start_row = 4)
## should all run without error
- wb$add_data_table(sheet = 1, x = df1, startCol = 3, startRow = 2)
- wb$add_data_table(sheet = 1, x = df1, startCol = 9, startRow = 2)
- wb$add_data_table(sheet = 1, x = df1, startCol = 4, startRow = 11)
- wb$add_data_table(sheet = 1, x = df1, startCol = 5, startRow = 11)
- wb$add_data_table(sheet = 1, x = df1, startCol = 6, startRow = 11)
- wb$add_data_table(sheet = 1, x = df1, startCol = 7, startRow = 11)
- wb$add_data_table(sheet = 1, x = df1, startCol = 8, startRow = 11)
- wb$add_data_table(sheet = 1, x = head(iris, 2), startCol = 4, startRow = 1)
+ wb$add_data_table(sheet = 1, x = df1, start_col = 3, start_row = 2)
+ wb$add_data_table(sheet = 1, x = df1, start_col = 9, start_row = 2)
+ wb$add_data_table(sheet = 1, x = df1, start_col = 4, start_row = 11)
+ wb$add_data_table(sheet = 1, x = df1, start_col = 5, start_row = 11)
+ wb$add_data_table(sheet = 1, x = df1, start_col = 6, start_row = 11)
+ wb$add_data_table(sheet = 1, x = df1, start_col = 7, start_row = 11)
+ wb$add_data_table(sheet = 1, x = df1, start_col = 8, start_row = 11)
+ wb$add_data_table(sheet = 1, x = head(iris, 2), start_col = 4, start_row = 1)
## Now error
- expect_error(wb$add_data_table(sheet = 1, x = df1, startCol = "H", startRow = 21), regexp = overwrite_table_error)
- expect_error(wb$add_data_table(sheet = 1, x = df1, startCol = 3, startRow = 12), regexp = overwrite_table_error)
- expect_error(wb$add_data_table(sheet = 1, x = df1, startCol = 9, startRow = 12), regexp = overwrite_table_error)
- expect_error(wb$add_data_table(sheet = 1, x = df1, startCol = "i", startRow = 12), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = df1, start_col = "H", start_row = 21), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = df1, start_col = 3, start_row = 12), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = df1, start_col = 9, start_row = 12), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = df1, start_col = "i", start_row = 12), regexp = overwrite_table_error)
## more errors
expect_error(wb$add_data_table(sheet = 1, x = head(iris)), regexp = overwrite_table_error)
- expect_error(wb$add_data_table(sheet = 1, x = head(iris), startCol = 4, startRow = 21), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris), start_col = 4, start_row = 21), regexp = overwrite_table_error)
## should work
- wb$add_data_table(sheet = 1, x = head(iris), startCol = 4, startRow = 22)
- wb$add_data_table(sheet = 1, x = head(iris), startCol = 4, startRow = 40)
+ wb$add_data_table(sheet = 1, x = head(iris), start_col = 4, start_row = 22)
+ wb$add_data_table(sheet = 1, x = head(iris), start_col = 4, start_row = 40)
## more errors
- expect_error(wb$add_data_table(sheet = 1, x = head(iris, 2), startCol = 4, startRow = 38), regexp = overwrite_table_error)
- expect_error(wb$add_data_table(sheet = 1, x = head(iris, 2), startCol = 4, startRow = 38, colNames = FALSE), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris, 2), start_col = 4, start_row = 38), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris, 2), start_col = 4, start_row = 38, col_names = FALSE), regexp = overwrite_table_error)
- expect_error(wb$add_data_table(sheet = 1, x = head(iris), startCol = "H", startRow = 40), regexp = overwrite_table_error)
- wb$add_data_table(sheet = 1, x = head(iris), startCol = "I", startRow = 40)
- wb$add_data_table(sheet = 1, x = head(iris)[, 1:3], startCol = "A", startRow = 40)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris), start_col = "H", start_row = 40), regexp = overwrite_table_error)
+ wb$add_data_table(sheet = 1, x = head(iris), start_col = "I", start_row = 40)
+ wb$add_data_table(sheet = 1, x = head(iris)[, 1:3], start_col = "A", start_row = 40)
- expect_error(wb$add_data_table(sheet = 1, x = head(iris, 2), startCol = 4, startRow = 38, colNames = FALSE), regexp = overwrite_table_error)
- expect_error(wb$add_data_table(sheet = 1, x = head(iris, 2), startCol = 1, startRow = 46, colNames = FALSE), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris, 2), start_col = 4, start_row = 38, col_names = FALSE), regexp = overwrite_table_error)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris, 2), start_col = 1, start_row = 46, col_names = FALSE), regexp = overwrite_table_error)
})
test_that("zero row data table works", {
@@ -68,34 +68,34 @@ test_that("write_data over tables", {
wb <- wb_add_worksheet(wb_workbook(), "Sheet1")
## table covers rows 4->10 and cols 4->8
- wb$add_data_table(sheet = 1, x = head(iris), startCol = 4, startRow = 4)
+ wb$add_data_table(sheet = 1, x = head(iris), start_col = 4, start_row = 4)
## Anywhere on row 5 is fine
for (i in 1:10) {
- wb$add_data(sheet = 1, x = head(iris), startRow = 5, startCol = i)
+ wb$add_data(sheet = 1, x = head(iris), start_row = 5, start_col = i)
}
## Anywhere on col i is fine
for (i in 1:10) {
- wb$add_data(sheet = 1, x = head(iris), startRow = i, startCol = "i")
+ wb$add_data(sheet = 1, x = head(iris), start_row = i, start_col = "i")
}
## Now errors on headers
- expect_error(wb$add_data(sheet = 1, x = head(iris), startCol = 4, startRow = 4), regexp = overwrite_table_error)
- wb$add_data(sheet = 1, x = head(iris), startCol = 4, startRow = 5)
+ expect_error(wb$add_data(sheet = 1, x = head(iris), start_col = 4, start_row = 4), regexp = overwrite_table_error)
+ wb$add_data(sheet = 1, x = head(iris), start_col = 4, start_row = 5)
wb$add_data(sheet = 1, x = head(iris)[1:3])
- wb$add_data(sheet = 1, x = head(iris, 2), startCol = 4)
- wb$add_data(sheet = 1, x = head(iris, 2), startCol = 4, colNames = FALSE)
+ wb$add_data(sheet = 1, x = head(iris, 2), start_col = 4)
+ wb$add_data(sheet = 1, x = head(iris, 2), start_col = 4, col_names = FALSE)
## Example of how this should be used
- wb$add_data_table(sheet = 1, x = head(iris), startCol = 4, startRow = 30)
- wb$add_data(sheet = 1, x = head(iris), startCol = 4, startRow = 31, colNames = FALSE)
+ wb$add_data_table(sheet = 1, x = head(iris), start_col = 4, start_row = 30)
+ wb$add_data(sheet = 1, x = head(iris), start_col = 4, start_row = 31, col_names = FALSE)
- wb$add_data_table(sheet = 1, x = head(iris), startCol = 10, startRow = 30)
- wb$add_data(sheet = 1, x = tail(iris), startCol = 10, startRow = 31, colNames = FALSE)
+ wb$add_data_table(sheet = 1, x = head(iris), start_col = 10, start_row = 30)
+ wb$add_data(sheet = 1, x = tail(iris), start_col = 10, start_row = 31, col_names = FALSE)
- wb$add_data_table(sheet = 1, x = head(iris)[, 1:3], startCol = 1, startRow = 30)
- wb$add_data(sheet = 1, x = tail(iris), startCol = 1, startRow = 31, colNames = FALSE)
+ wb$add_data_table(sheet = 1, x = head(iris)[, 1:3], start_col = 1, start_row = 30)
+ wb$add_data(sheet = 1, x = tail(iris), start_col = 1, start_row = 31, col_names = FALSE)
})
test_that("Validate Table Names", {
@@ -127,15 +127,15 @@ test_that("Existing Table Names", {
wb <- wb_add_worksheet(wb_workbook(), "Sheet 1")
## Existing names - case in-sensitive
- wb$add_data_table(sheet = 1, x = head(iris), tableName = "Table1")
+ wb$add_data_table(sheet = 1, x = head(iris), table_name = "Table1")
expect_error(wb_validate_table_name(wb, "Table1"), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
- expect_error(wb$add_data_table(sheet = 1, x = head(iris), table_name = "Table1", startCol = 10), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris), table_name = "Table1", start_col = 10), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
expect_error(wb_validate_table_name(wb, "TABLE1"), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
- expect_error(wb$add_data_table(sheet = 1, x = head(iris), tableName = "TABLE1", startCol = 20), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris), table_name = "TABLE1", start_col = 20), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
expect_error(wb_validate_table_name(wb, "table1"), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
- expect_error(wb$add_data_table(sheet = 1, x = head(iris), tableName = "table1", startCol = 30), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
+ expect_error(wb$add_data_table(sheet = 1, x = head(iris), table_name = "table1", start_col = 30), regexp = "`table_name = 'table1'` already exists", fixed = TRUE)
})
test_that("custom table styles work", {
@@ -145,10 +145,10 @@ test_that("custom table styles work", {
wb_add_worksheet()
# create dxf elements to be used in the table style
- tabCol1 <- create_dxfs_style(bgFill = wb_color(theme = 7))
- tabCol2 <- create_dxfs_style(bgFill = wb_color(theme = 5))
+ tabCol1 <- create_dxfs_style(bg_fill = wb_color(theme = 7))
+ tabCol2 <- create_dxfs_style(bg_fill = wb_color(theme = 5))
tabBrd1 <- create_dxfs_style(border = TRUE)
- tabCol3 <- create_dxfs_style(bgFill = wb_color(hex = "FFC00000"), font_color = wb_color("white"))
+ tabCol3 <- create_dxfs_style(bg_fill = wb_color(hex = "FFC00000"), font_color = wb_color("white"))
# don't forget to assign them to the workbook
wb$add_style(tabCol1)
@@ -174,9 +174,9 @@ test_that("custom table styles work", {
)
wb$add_style(tab_xml)
- expect_silent(wb$add_data_table(x = mtcars, tableStyle = "RedTableStyle"))
+ expect_silent(wb$add_data_table(x = mtcars, table_style = "RedTableStyle"))
wb$add_worksheet()
- expect_error(wb$add_data_table(x = mtcars, tableStyle = "RedTableStyle1"), "Invalid table style.")
+ expect_error(wb$add_data_table(x = mtcars, table_style = "RedTableStyle1"), "Invalid table style.")
})
@@ -199,8 +199,7 @@ test_that("updating table works", {
wb <- wb_workbook()$add_worksheet()$add_data_table(x = mtcars, with_filter = FALSE)
wb$update_table(tabname = "Table1", dims = "A1:J4")
- exp <- "A1:J4"
got <- wb$tables$tab_ref
- expect_equal(exp, got)
+ expect_equal(got, "A1:J4")
})
diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R
index 07f127706..0effd4907 100644
--- a/tests/testthat/test-utils.R
+++ b/tests/testthat/test-utils.R
@@ -274,13 +274,13 @@ test_that("test random_string", {
tmp <- random_string()
y <- .Random.seed
expect_identical(x, y)
- expect_equal("HmPsw2WtYSxSgZ6t", tmp)
+ expect_equal(tmp, "HmPsw2WtYSxSgZ6t")
x <- .Random.seed
tmp <- random_string(length = 6)
y <- .Random.seed
expect_identical(x, y)
- expect_equal("GNZuCt", tmp)
+ expect_equal(tmp, "GNZuCt")
x <- .Random.seed
tmp <- random_string(length = 6, keep_seed = FALSE)
@@ -301,22 +301,22 @@ test_that("relship", {
exp <- ""
got <- relship_no(obj = wb$worksheets_rels[[3]], x = "table")
- expect_equal(exp, got)
+ expect_equal(got, exp)
- exp <- "rId2"
got <- get_relship_id(obj = wb$worksheets_rels[[1]], x = "drawing")
- expect_equal(exp, got)
+ expect_equal(got, "rId2")
})
test_that("as_xml_attr works", {
mm <- matrix("", 2, 2)
- mm[1, 1] <- openxlsx2:::as_xml_attr(TRUE)
- mm[2, 1] <- openxlsx2:::as_xml_attr(FALSE)
+ # as_xml_attr is internal
+ mm[1, 1] <- as_xml_attr(TRUE)
+ mm[2, 1] <- as_xml_attr(FALSE)
- mm[1, 2] <- openxlsx2:::as_xml_attr(1)
- mm[2, 2] <- openxlsx2:::as_xml_attr(NULL)
+ mm[1, 2] <- as_xml_attr(1)
+ mm[2, 2] <- as_xml_attr(NULL)
exp <- matrix(c("1", "0", "1", ""), 2, 2)
expect_equal(exp, mm)
@@ -401,8 +401,7 @@ test_that("fmt_txt works", {
expect_equal(exp, got)
expect_message(got <- capture.output(print(got)), "fmt_txt string:")
- exp <- "[1] \"Hello World \""
- expect_equal(exp, got)
+ expect_equal(got, "[1] \"Hello World \"")
## watch out!
txt <- fmt_txt("Sum ", bold = TRUE) + 2 + 2
diff --git a/tests/testthat/test-wb_functions.R b/tests/testthat/test-wb_functions.R
index c4352d96f..d81f1172d 100644
--- a/tests/testthat/test-wb_functions.R
+++ b/tests/testthat/test-wb_functions.R
@@ -23,10 +23,10 @@ test_that("wb_to_df", {
class = "data.frame"
)
got <- wb_to_df(wb1)
- expect_equal(exp, got, ignore_attr = TRUE)
+ expect_equal(got, exp, ignore_attr = TRUE)
# do not convert first row to colNames
- got <- wb_to_df(wb1, colNames = FALSE)
+ got <- wb_to_df(wb1, col_names = FALSE)
expect_equal(int2col(seq_along(got)), names(got))
# do not try to identify dates in the data
@@ -38,10 +38,10 @@ test_that("wb_to_df", {
# return the underlying Excel formula instead of their values
got <- wb_to_df(wb1, showFormula = TRUE)
- expect_equal("1/0", got$Var7[1])
+ expect_equal(got$Var7[1], "1/0")
- # read dimension withot colNames
- got <- wb_to_df(wb1, dims = "A2:C5", colNames = FALSE)
+ # read dimension without colNames
+ got <- wb_to_df(wb1, dims = "A2:C5", col_names = FALSE)
test <- data.frame(A = c(TRUE, TRUE, TRUE, FALSE),
B = c(1, NA, 2, 2),
C = rep(NA_real_, 4))
@@ -68,14 +68,14 @@ test_that("wb_to_df", {
# # erase empty Rows from dataset
# not gonna test this :) just want to mention how blazing fast it is now.
- # got <- wb_to_df(wb1, sheet = 3, skipEmptyRows = TRUE)
+ # got <- wb_to_df(wb1, sheet = 3, skip_empty_rows = TRUE)
# erase rmpty Cols from dataset
- got <- wb_to_df(wb1, skipEmptyCols = TRUE)
+ got <- wb_to_df(wb1, skip_empty_cols = TRUE)
expect_equal(exp[c(1, 2, 4, 5, 6, 7, 8)], got, ignore_attr = TRUE)
# # convert first row to rownames
- # wb_to_df(wb1, sheet = 3, dims = "C6:G9", rowNames = TRUE)
+ # wb_to_df(wb1, sheet = 3, dims = "C6:G9", row_names = TRUE)
# define type of the data.frame
got <- wb_to_df(wb1, cols = c(1, 4), types = c("Var1" = 0, "Var3" = 1))
@@ -89,11 +89,11 @@ test_that("wb_to_df", {
test <- exp[4:10, ]
names(test) <- int2col(seq_along(test))
test[c("D", "G", "H")] <- lapply(test[c("D", "G", "H")], as.numeric)
- expect_equal(test, got, ignore_attr = TRUE)
+ expect_equal(got, test, ignore_attr = TRUE)
# na string
got <- wb_to_df(wb1, na.strings = "")
- expect_equal("#N/A", got$Var7[2], ignore_attr = TRUE)
+ expect_equal(got$Var7[2], "#N/A", ignore_attr = TRUE)
###########################################################################
@@ -113,7 +113,7 @@ test_that("wb_to_df", {
rownames(exp) <- seq(2, nrow(exp) + 1)
# read dataset with inlinestr
got <- wb_to_df(wb2)
- expect_equal(exp, got, ignore_attr = TRUE)
+ expect_equal(got, exp, ignore_attr = TRUE)
###########################################################################
@@ -122,14 +122,14 @@ test_that("wb_to_df", {
expect_silent(wb3 <- wb_load(xlsxFile))
# read dataset with named_region (returns global first)
+ got <- wb_to_df(wb3, named_region = "MyRange", col_names = FALSE)
exp <- data.frame(A = "S2A1", B = "S2B1")
- got <- wb_to_df(wb3, named_region = "MyRange", colNames = FALSE)
- expect_equal(exp, got, ignore_attr = TRUE)
+ expect_equal(got, exp, ignore_attr = TRUE)
# read named_region from sheet
+ got <- wb_to_df(wb3, named_region = "MyRange", sheet = 4, col_names = FALSE)
exp <- data.frame(A = "S3A1", B = "S3B1")
- got <- wb_to_df(wb3, named_region = "MyRange", sheet = 4, colNames = FALSE)
- expect_equal(exp, got, ignore_attr = TRUE)
+ expect_equal(got, exp, ignore_attr = TRUE)
})
@@ -145,7 +145,7 @@ test_that("select_active_sheet", {
row.names = c(NA, 4L), class = "data.frame")
# testing is the selected sheet
- expect_identical(exp, wb_get_selected(wb))
+ expect_identical(wb_get_selected(wb), exp)
# change the selected sheet to IrisSample
exp <- structure(
@@ -155,14 +155,14 @@ test_that("select_active_sheet", {
row.names = c(NA, 4L), class = "data.frame")
wb <- wb_set_selected(wb, "IrisSample")
- expect_identical(exp, wb_get_selected(wb))
+ expect_identical(wb_get_selected(wb), exp)
# get the active sheet
- expect_identical(2, wb_get_active_sheet(wb))
+ expect_identical(wb_get_active_sheet(wb), 2)
# change the selected sheet to IrisSample
wb <- wb_set_active_sheet(wb, sheet = "IrisSample")
- expect_identical(1, wb_get_active_sheet(wb))
+ expect_identical(wb_get_active_sheet(wb), 1)
})
@@ -218,10 +218,10 @@ test_that("handle 29Feb1900", {
add_worksheet()$add_data(x = as_date)$
add_worksheet()$add_data(x = as_posix)
- got <- wb_to_df(wb, sheet = 1, colNames = FALSE)$A
+ got <- wb_to_df(wb, sheet = 1, col_names = FALSE)$A
expect_equal(as_date, got)
- got <- wb_to_df(wb, sheet = 2, colNames = FALSE)$A
+ got <- wb_to_df(wb, sheet = 2, col_names = FALSE)$A
expect_equal(as_posix, got)
})
@@ -229,12 +229,12 @@ test_that("handle 29Feb1900", {
test_that("fillMergedCells works with dims", {
- # create data frame with emtpy second row
+ # create data frame with empty second row
wb <- wb_workbook()$
add_worksheet()$
- add_data(x = t(letters[1:4]), colNames = FALSE)$
+ add_data(x = t(letters[1:4]), col_names = FALSE)$
add_data(1, t(matrix(c(1:3, NA_real_), 4, 4)),
- startRow = 3, startCol = 1, colNames = FALSE)
+ start_row = 3, start_col = 1, col_names = FALSE)
# merge rows 1 and 2 in each column
wb$merge_cells(1, rows = 1:2, cols = 1)
@@ -243,11 +243,10 @@ test_that("fillMergedCells works with dims", {
wb$merge_cells(1, rows = 1:2, cols = 4)
# read from second column and fill merged cells
- got <- wb_to_df(wb, dims = "A2:D4", fillMergedCells = TRUE)
+ got <- wb_to_df(wb, dims = "A2:D4", fill_merged_cells = TRUE)
exp <- c("a", "b", "c", "d")
- got <- names(got)
- expect_equal(exp, got)
+ expect_equal(names(got), exp)
})
@@ -255,9 +254,9 @@ test_that("improve date detection", {
df <- wb_workbook() %>%
wb_add_worksheet("Rawdata") %>%
- wb_add_data(x = Sys.Date(), colNames = FALSE) %>%
+ wb_add_data(x = Sys.Date(), col_names = FALSE) %>%
wb_add_numfmt(numfmt = "[$-1070000]d/mm/yyyy;@") %>%
- wb_to_df(colNames = FALSE)
+ wb_to_df(col_names = FALSE)
exp <- Sys.Date()
got <- df$A
@@ -274,15 +273,14 @@ test_that("skip hidden columns and rows works", {
set_row_heights(rows = c(3, 5, 8:30), hidden = TRUE)$
add_data(dims = "M1", x = iris)
- dat <- wb_to_df(wb, dims = "A1:K33", skipHiddenRows = TRUE, skipHiddenCols = TRUE)
+ dat <- wb_to_df(wb, dims = "A1:K33", skip_hidden_rows = TRUE, skip_hidden_cols = TRUE)
exp <- c("2", "4", "6", "7", "31", "32", "33")
got <- rownames(dat)
- expect_equal(exp, got)
+ expect_equal(rownames(dat), exp)
exp <- c("cyl", "disp", "drat", "vs", "gear", "carb")
- got <- names(dat)
- expect_equal(exp, got)
+ expect_equal(names(dat), exp)
})
diff --git a/tests/testthat/test-wb_styles.R b/tests/testthat/test-wb_styles.R
index 3081bf926..31c243d82 100644
--- a/tests/testthat/test-wb_styles.R
+++ b/tests/testthat/test-wb_styles.R
@@ -331,16 +331,16 @@ test_that("get & set cell style(s)", {
# get style from b1 to assign it to a1
numfmt <- wb$get_cell_style(dims = "B1")
- expect_equal("1", numfmt)
+ expect_equal(numfmt, "1")
# assign style to a1
pre <- wb$get_cell_style(dims = "A1")
- expect_equal("", pre)
+ expect_equal(pre, "")
expect_silent(wb$set_cell_style(dims = "A1", style = numfmt))
post <- wb$get_cell_style(dims = "A1")
- expect_equal("1", post)
+ expect_equal(post, "1")
s_a1_b1 <- wb$get_cell_style(dims = "A1:B1")
expect_silent(wb$set_cell_style(dims = "A2:B2", style = s_a1_b1))
@@ -367,21 +367,19 @@ test_that("get_cell_styles()", {
right_border = "",
top_border = "")
- exp <- "1"
got <- wb$get_cell_style(dims = "B2")
- expect_equal(exp, got)
+ expect_equal(got, "1")
exp <- ""
got <- get_cell_styles(wb, 1, "B2")
- expect_equal(exp, got)
+ expect_equal(got, exp)
- exp <- "3"
got <- wb$get_cell_style(dims = "B3")
- expect_equal(exp, got)
+ expect_equal(got, "3")
exp <- ""
got <- get_cell_styles(wb, 1, "B3")
- expect_equal(exp, got)
+ expect_equal(got, exp)
wb$add_cell_style(dims = "B3:L3",
textRotation = "45",
@@ -391,7 +389,7 @@ test_that("get_cell_styles()", {
exp <- ""
got <- get_cell_styles(wb, 1, "B3")
- expect_equal(exp, got)
+ expect_equal(got, exp)
})
diff --git a/tests/testthat/test-write.R b/tests/testthat/test-write.R
index 553bd431b..a0e05628f 100644
--- a/tests/testthat/test-write.R
+++ b/tests/testthat/test-write.R
@@ -18,7 +18,7 @@ test_that("write_formula", {
wb <- wb_workbook()
wb <- wb_add_worksheet(wb, "df")
wb$add_data("df", df, startCol = "C")
- write_formula(wb, "df", startCol = "E", startRow = 2,
+ write_formula(wb, "df", start_col = "E", start_row = 2,
x = "SUM(C2:C11*D2:D11)",
array = TRUE)
@@ -31,10 +31,10 @@ test_that("write_formula", {
# write formula first add data later
wb <- wb_workbook()
wb <- wb_add_worksheet(wb, "df")
- write_formula(wb, "df", startCol = "E", startRow = 2,
+ write_formula(wb, "df", start_col = "E", start_row = 2,
x = "SUM(C2:C11*D2:D11)",
array = TRUE)
- wb$add_data("df", df, startCol = "C")
+ wb$add_data("df", df, start_col = "C")
cc <- wb$worksheets[[1]]$sheet_data$cc
got <- cc[cc$row_r == "2" & cc$c_r == "E", ]
@@ -50,19 +50,19 @@ test_that("silent with numfmt option", {
wb$add_data_table("S1", x = iris)
wb$add_data_table("S2",
- x = mtcars, dims = "B3", rowNames = TRUE,
- tableStyle = "TableStyleLight9")
+ x = mtcars, dims = "B3", row_names = TRUE,
+ table_style = "TableStyleLight9")
# [1:4] to ignore factor
expect_equal(iris[1:4], wb_to_df(wb, "S1")[1:4], ignore_attr = TRUE)
expect_equal(iris[1:4], wb_to_df(wb, "S1")[1:4], ignore_attr = TRUE)
# handle rownames
- got <- wb_to_df(wb, "S2", rowNames = TRUE)
+ got <- wb_to_df(wb, "S2", row_names = TRUE)
attr(got, "tt") <- NULL
attr(got, "types") <- NULL
- expect_equal(mtcars, got)
- expect_equal(rownames(mtcars), rownames(got))
+ expect_equal(got, mtcars)
+ expect_equal(rownames(got), rownames(mtcars))
})
@@ -111,15 +111,14 @@ test_that("update_cells", {
wb <- wb_workbook()$
add_worksheet("df")$
- add_data(x = df, startCol = "C")
- # TODO add_formula()
- write_formula(wb, "df", startCol = "E", startRow = 2,
+ add_data(x = df, start_col = "C")
+ wb$add_formula("df", start_col = "E", start_row = 2,
x = "SUM(C2:C11*D2:D11)",
array = TRUE)
- write_formula(wb, "df", x = "C3 + D3", startCol = "E", startRow = 3)
+ wb$add_formula("df", x = "C3 + D3", start_col = "E", start_row = 3)
x <- c(google = "https://www.google.com")
class(x) <- "hyperlink"
- wb$add_data(sheet = "df", x = x, startCol = "E", startRow = 4)
+ wb$add_data(sheet = "df", x = x, start_col = "E", start_row = 4)
exp <- structure(
@@ -147,13 +146,13 @@ test_that("write dims", {
# create a workbook
wb <- wb_workbook()$
- add_worksheet()$add_data(dims = "B2:C3", x = matrix(1:4, 2, 2), colNames = FALSE)$
+ add_worksheet()$add_data(dims = "B2:C3", x = matrix(1:4, 2, 2), col_names = FALSE)$
add_worksheet()$add_data_table(dims = "B:C", x = as.data.frame(matrix(1:4, 2, 2)))$
add_worksheet()$add_formula(dims = "B3", x = "42")
- s1 <- wb_to_df(wb, 1, colNames = FALSE)
- s2 <- wb_to_df(wb, 2, colNames = FALSE)
- s3 <- wb_to_df(wb, 3, colNames = FALSE)
+ s1 <- wb_to_df(wb, 1, col_names = FALSE)
+ s2 <- wb_to_df(wb, 2, col_names = FALSE)
+ s3 <- wb_to_df(wb, 3, col_names = FALSE)
expect_equal(rownames(s1), c("2", "3"))
expect_equal(rownames(s2), c("1", "2", "3"))
@@ -233,8 +232,8 @@ test_that("update cell(s)", {
test_that("write_rownames", {
wb <- wb_workbook()$
- add_worksheet()$add_data(x = mtcars, rowNames = TRUE)$
- add_worksheet()$add_data_table(x = mtcars, rowNames = TRUE)
+ add_worksheet()$add_data(x = mtcars, row_names = TRUE)$
+ add_worksheet()$add_data_table(x = mtcars, row_names = TRUE)
exp <- structure(
list(A = c(NA, "Mazda RX4"), B = c("mpg", "21")),
@@ -246,7 +245,7 @@ test_that("write_rownames", {
class = "data.frame"),
types = c(A = 0, B = 0)
)
- got <- wb_to_df(wb, 1, dims = "A1:B2", colNames = FALSE, keep_attributes = TRUE)
+ got <- wb_to_df(wb, 1, dims = "A1:B2", col_names = FALSE, keep_attributes = TRUE)
expect_equal(exp, got)
exp <- structure(
@@ -259,7 +258,7 @@ test_that("write_rownames", {
class = "data.frame"),
types = c(A = 0, B = 0)
)
- got <- wb_to_df(wb, 2, dims = "A1:B2", colNames = FALSE, keep_attributes = TRUE)
+ got <- wb_to_df(wb, 2, dims = "A1:B2", col_names = FALSE, keep_attributes = TRUE)
expect_equal(exp, got)
})
@@ -280,7 +279,7 @@ test_that("NA works as expected", {
)
exp <- c(NA_real_, NA_real_)
- got <- wb_to_df(wb, colNames = FALSE)$A
+ got <- wb_to_df(wb, col_names = FALSE)$A
expect_equal(exp, got)
})
@@ -293,11 +292,11 @@ test_that("writeData() forces evaluation of x (#264)", {
wb <- wb_workbook()
wb$add_worksheet("sheet")
- wb$add_data(startCol = 1, x = data.frame(a = format(123.4)))
- wb$add_data(startCol = 2, x = data.frame(b = as.character(123.4)))
- wb$add_data(startCol = 3, x = data.frame(c = "123.4"))
- wb$add_data(startCol = 4, x = df)
- wb$add_data(startCol = 5, x = df2)
+ wb$add_data(start_col = 1, x = data.frame(a = format(123.4)))
+ wb$add_data(start_col = 2, x = data.frame(b = as.character(123.4)))
+ wb$add_data(start_col = 3, x = data.frame(c = "123.4"))
+ wb$add_data(start_col = 4, x = df)
+ wb$add_data(start_col = 5, x = df2)
exp <- c(
"a", "b", "c",
@@ -318,9 +317,8 @@ test_that("write character numerics with a correct cell style", {
wb_add_worksheet() %>%
wb_add_data(x = c("One", "2", "Three", "1.7976931348623157E+309", "2.5"))
- exp <- NA_character_
got <- wb$styles_mgr$styles$cellXfs[2]
- expect_equal(exp, got)
+ expect_equal(got, NA_character_)
exp <- c("4", "4", "4", "4", "4")
got <- wb$worksheets[[1]]$sheet_data$cc$typ
@@ -365,9 +363,8 @@ test_that("write character numerics with a correct cell style", {
wb_add_worksheet() %>%
wb_add_data(x = c("One", "2", "Three", "1.7976931348623157E+309", "2.5"))
- exp <- NA_character_
got <- wb$styles_mgr$styles$cellXfs[2]
- expect_equal(exp, got)
+ expect_equal(got, NA_character_)
exp <- c("4", "2", "4", "4", "2")
got <- wb$worksheets[[1]]$sheet_data$cc$typ
@@ -394,7 +391,7 @@ test_that("writing as shared string works", {
add_worksheet()$
add_data_table(x = df, inline_strings = TRUE)
- expect_equal(letters, wb_to_df(wb, colNames = FALSE)$A)
+ expect_equal(letters, wb_to_df(wb, col_names = FALSE)$A)
expect_equal(wb_to_df(wb, 1), wb_to_df(wb, 2))
expect_equal(df, wb_to_df(wb, 3), ignore_attr = TRUE)
expect_equal(wb_to_df(wb, 3), wb_to_df(wb, 4))
@@ -445,7 +442,7 @@ test_that("writing as shared string works", {
add_data(x = c(1L, NA, NaN, Inf), dims = "A1", inline_strings = FALSE, na.strings = NULL)
expect_equal(wb_to_df(wb, 1), wb_to_df(wb, 3))
- expect_equal("N/A", wb_to_df(wb, 2)[1, 1])
+ expect_equal(wb_to_df(wb, 2)[1, 1], "N/A")
})
@@ -462,7 +459,7 @@ test_that("writing pivot tables works", {
wb$add_pivot_table(df, dims = "A20", sheet = 2, rows = "cyl", cols = "gear", data = c("disp", "hp"), fun = "average")
wb$add_pivot_table(df, dims = "A30", sheet = 2, rows = "cyl", cols = "gear", data = c("disp", "hp"), fun = c("sum", "average"))
- expect_equal(4L, length(wb$pivotTables))
+ expect_equal(length(wb$pivotTables), 4L)
})
@@ -523,12 +520,12 @@ test_that("writing slicers works", {
add_slicer(x = df, dims = "A12:D16", slicer = "vs", pivot_table = "mtcars3")
# test a few conditions
- expect_equal(2L, length(wb$slicers))
- expect_equal(4L, length(wb$slicerCaches))
+ expect_length(wb$slicers, 2L)
+ expect_length(wb$slicerCaches, 4L)
expect_equal(xml_node_name(wb$workbook$extLst, "extLst", "ext"), "x14:slicerCaches")
- expect_equal(1L, wb$worksheets[[2]]$relships$slicer)
- expect_equal(2L, wb$worksheets[[3]]$relships$slicer)
- expect_equal(25L, grep("slicer2.xml", wb$Content_Types))
+ expect_equal(wb$worksheets[[2]]$relships$slicer, 1L)
+ expect_equal(wb$worksheets[[3]]$relships$slicer, 2L)
+ expect_equal(grep("slicer2.xml", wb$Content_Types), 25L)
## test error
wb <- wb_workbook() %>%
@@ -652,7 +649,7 @@ test_that("writing labeled variables works", {
wb <- wb_workbook()$add_worksheet()$add_data(x = x)
exp <- c(1, 2)
- got <- wb_to_df(wb, colNames = FALSE)$A
+ got <- wb_to_df(wb, col_names = FALSE)$A
expect_equal(exp, got)
})
@@ -687,7 +684,7 @@ test_that("writing in specific encoding works", {
# got <- wb2$worksheets[[1]]$sheet_data$cc$is[1]
# expect_equal(exp, got)
- # got <- stringi::stri_encode(wb_to_df(wb, colNames = FALSE)$A, from = "UTF-8", to = "CP1251")
+ # got <- stringi::stri_encode(wb_to_df(wb, col_names = FALSE)$A, from = "UTF-8", to = "CP1251")
# expect_equal(enc_str, got)
tmp <- tempfile()
diff --git a/tests/testthat/test-writing_posixct.R b/tests/testthat/test-writing_posixct.R
index 92a6af834..3800b5176 100644
--- a/tests/testthat/test-writing_posixct.R
+++ b/tests/testthat/test-writing_posixct.R
@@ -10,8 +10,8 @@ test_that("Writing Posixct with write_data & write_datatable", {
wb$add_worksheet("write_data")
wb$add_worksheet("write_datatable")
- wb$add_data("write_data", df, startCol = 2, startRow = 3, rowNames = FALSE)
- wb$add_data_table("write_datatable", df, startCol = 2, startRow = 3)
+ wb$add_data("write_data", df, start_col = 2, start_row = 3, row_names = FALSE)
+ wb$add_data_table("write_datatable", df, start_col = 2, start_row = 3)
# wb_open(wb)
@@ -42,8 +42,8 @@ test_that("Writing mixed EDT/EST Posixct with write_data & write_datatable", {
wb$add_worksheet("write_data")
wb$add_worksheet("write_datatable")
- wb$add_data("write_data", df, startCol = 2, startRow = 3, rowNames = FALSE)
- wb$add_data_table("write_datatable", df, startCol = 2, startRow = 3)
+ wb$add_data("write_data", df, start_col = 2, start_row = 3, row_names = FALSE)
+ wb$add_data_table("write_datatable", df, start_col = 2, start_row = 3)
xlsxFile <- temp_xlsx()
wb_save(wb, xlsxFile, TRUE)