Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snake case conversion. #943

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions R/class-workbook-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -1674,10 +1674,10 @@ wb_set_header_footer <- function(
#' wb$add_worksheet("print_title_cols")
#'
#' wb$add_data("print_title_rows", rbind(iris, iris, iris, iris))
#' wb$add_data("print_title_cols", x = rbind(mtcars, mtcars, mtcars), rowNames = TRUE)
#' wb$add_data("print_title_cols", x = rbind(mtcars, mtcars, mtcars), row_names = TRUE)
#'
#' wb$page_setup(sheet = "print_title_rows", printTitleRows = 1) ## first row
#' wb$page_setup(sheet = "print_title_cols", printTitleCols = 1, printTitleRows = 1)
#' wb$page_setup(sheet = "print_title_rows", print_title_rows = 1) ## first row
#' wb$page_setup(sheet = "print_title_cols", print_title_cols = 1, print_title_rows = 1)
wb_page_setup <- function(
wb,
sheet = current_sheet(),
Expand Down Expand Up @@ -1897,19 +1897,19 @@ wb_grid_lines <- function(wb, sheet = current_sheet(), show = FALSE, print = sho
#' @examples
#' ## setup a workbook with 3 worksheets
#' wb <- wb_workbook()
#' wb$add_worksheet("Sheet 1", gridLines = FALSE)
#' wb$add_data_table(sheet = 1, x = iris)
#' wb$add_worksheet("Sheet 1", grid_lines = FALSE)
#' wb$add_data_table(x = iris)
#'
#' wb$add_worksheet("mtcars (Sheet 2)", gridLines = FALSE)
#' wb$add_data(sheet = 2, x = mtcars)
#' wb$add_worksheet("mtcars (Sheet 2)", grid_lines = FALSE)
#' wb$add_data(x = mtcars)
#'
#' wb$add_worksheet("Sheet 3", gridLines = FALSE)
#' wb$add_data(sheet = 3, x = Formaldehyde)
#' wb$add_worksheet("Sheet 3", grid_lines = FALSE)
#' wb$add_data(x = Formaldehyde)
#'
#' wb_get_order(wb)
#' wb$get_sheet_na
#' wb$set_order(c(1, 3, 2)) # switch position of sheets 2 & 3
#' wb$add_data(2, 'This is still the "mtcars" worksheet', startCol = 15)
#' wb$add_data(2, 'This is still the "mtcars" worksheet', start_col = 15)
#' wb_get_order(wb)
#' wb$get_sheet_names() ## ordering within workbook is not changed
#' wb$set_order(3:1)
Expand Down Expand Up @@ -2059,7 +2059,7 @@ wb_remove_named_region <- function(wb, sheet = current_sheet(), name = NULL) {
#' wb$add_filter(1, row = 1, cols = seq_along(iris))
#'
#' ## Equivalently
#' wb$add_data(2, x = iris, withFilter = TRUE)
#' wb$add_data(2, x = iris, with_filter = TRUE)
#'
#' ## Similarly
#' wb$add_data_table(3, iris)
Expand Down Expand Up @@ -2354,7 +2354,7 @@ wb_remove_tables <- function(wb, sheet = current_sheet(), table, remove_data = T
#'
#' wb <- wb_workbook()
#' wb$add_worksheet("AirPass")
#' wb$add_data("AirPass", t2, rowNames = TRUE)
#' wb$add_data("AirPass", t2, row_names = TRUE)
#'
#' # groups will always end on/show the last row. in the example 1950, 1955, and 1960
#' wb <- wb_group_rows(wb, "AirPass", 2:3, collapsed = TRUE) # group years < 1950
Expand Down Expand Up @@ -2409,7 +2409,7 @@ wb_ungroup_cols <- function(wb, sheet = current_sheet(), cols) {
#'
#' wb <- wb_workbook()
#' wb$add_worksheet("AirPass")
#' wb$add_data("AirPass", t2, rowNames = TRUE)
#' wb$add_data("AirPass", t2, row_names = TRUE)
#'
#' wb$group_cols("AirPass", cols = grp_cols)
#' wb$group_rows("AirPass", rows = grp_rows)
Expand Down
4 changes: 3 additions & 1 deletion R/write_xlsx.R
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ write_xlsx <- function(x, file, as_table = FALSE, ...) {
}

for (i in seq_len(nSheets)) {
wb$add_worksheet(nms[[i]], gridLines = gridLines[i], tabColor = tabColor[i], zoom = zoom[i])
wb$add_worksheet(nms[[i]], grid_lines = gridLines[i], tab_color = tabColor[i], zoom = zoom[i])

if (as_table[i]) {
# add data table??
write_datatable(
wb = wb,
sheet = i,
Expand All @@ -358,6 +359,7 @@ write_xlsx <- function(x, file, as_table = FALSE, ...) {
na.strings = na.strings
)
} else {
# TODO add_data()?
olivroy marked this conversation as resolved.
Show resolved Hide resolved
write_data(
wb = wb,
sheet = i,
Expand Down
2 changes: 1 addition & 1 deletion man/filter-wb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/grouping-wb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions man/wb_order.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/wb_page_setup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tests/testthat/test-helper-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test_that("openxlsx2_types", {
z <- complex(real = stats::rnorm(1), imaginary = stats::rnorm(1))
expect_equal(openxlsx2_celltype[["character"]], openxlsx2_type(z))

# write_datatable example: data frame with various types
# wb_add_data_table() example: data frame with various types
df <- data.frame(
"Date" = Sys.Date() - 0:19,
"T" = TRUE, "F" = FALSE,
Expand All @@ -33,8 +33,8 @@ test_that("openxlsx2_types", {
got <- openxlsx2_type(df)
exp <- c(
Date = openxlsx2_celltype[["short_date"]],
T = openxlsx2_celltype[["logical"]],
F = openxlsx2_celltype[["logical"]],
`T` = openxlsx2_celltype[["logical"]],
`F` = openxlsx2_celltype[["logical"]],
Time = openxlsx2_celltype[["long_date"]],
Cash = openxlsx2_celltype[["currency"]],
Cash2 = openxlsx2_celltype[["accounting"]],
Expand Down Expand Up @@ -78,10 +78,10 @@ test_that("wb_page_setup example", {
wb$add_worksheet("print_title_cols")

wb$add_data("print_title_rows", rbind(iris, iris, iris, iris))
wb$add_data("print_title_cols", x = rbind(mtcars, mtcars, mtcars), rowNames = TRUE)
wb$add_data("print_title_cols", x = rbind(mtcars, mtcars, mtcars), row_names = TRUE)

wb$page_setup(sheet = "print_title_rows", printTitleRows = 1) ## first row
wb$page_setup(sheet = "print_title_cols", printTitleCols = 1, printTitleRows = 1)
wb$page_setup(sheet = "print_title_rows", print_title_rows = 1) ## first row
wb$page_setup(sheet = "print_title_cols", print_title_cols = 1, print_title_rows = 1)

exp <- c(
"<definedName localSheetId=\"2\" name=\"_xlnm.Print_Titles\">'print_title_rows'!$1:$1</definedName>",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-tables.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

test_that("write_datatable over tables", {
test_that("add_data_table() writes over tables", {

overwrite_table_error <- "Cannot overwrite existing table with another table"
df1 <- data.frame("X" = 1:10)
Expand Down