Skip to content

Commit

Permalink
use default argument over %||%
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Nov 14, 2023
1 parent f102096 commit a50e2e5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion R/class-comment.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ wb_comment <- function(text = NULL,
width = 2,
height = 4) {
# Code copied from the wbWorkbook
author <- author %||% Sys.getenv("USERNAME")
author <- author %||% Sys.getenv("USERNAME") %||% Sys.getenv("USER")
text <- text %||% ""
assert_class(author, "character")
assert_class(text, "character")
Expand Down
15 changes: 8 additions & 7 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ wbWorkbook <- R6::R6Class(
self$Content_Types <- genBaseContent_Type()

creator <- creator %||%
getOption("openxlsx2.creator") %||%
getOption("openxlsx2.creator", default = Sys.getenv("USERNAME")) %||%
# USERNAME may only be present for windows
Sys.getenv("USERNAME", Sys.getenv("USER"))
Sys.getenv("USER")

datetime_created <- getOption("openxlsx2.datetimeCreated", datetime_created)

datetime_created <- getOption("openxlsx2.datetimeCreated") %||%
datetime_created

assert_class(creator, "character")
assert_class(title, "character", or_null = TRUE)
Expand Down Expand Up @@ -4269,7 +4269,7 @@ wbWorkbook <- R6::R6Class(
done <- as_xml_attr(resolve)
if (reply) done <- NULL

ts <- getOption("openxlsx2.datetimeCreated") %||% Sys.time()
ts <- getOption("openxlsx2.datetimeCreated", default = Sys.time())

tc <- xml_node_create(
"threadedComment",
Expand Down Expand Up @@ -5587,8 +5587,9 @@ wbWorkbook <- R6::R6Class(
company = NULL
) {

datetime_created <- getOption("openxlsx2.datetimeCreated") %||%
datetime_created
datetime_created <-
getOption("openxlsx2.datetimeCreated", datetime_created)


core_dctitle <- "dc:title"
core_subject <- "dc:subject"
Expand Down
4 changes: 2 additions & 2 deletions R/conditional_formatting.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ cf_create_databar <- function(extLst, formula, params, sqref, values) {
newExtLst <- gen_databar_extlst(
guid = guid,
sqref = sqref,
posColor = posColor,
negColor = negColor,
posColor = posColor,
negColor = negColor,
values = values,
border = border,
gradient = gradient
Expand Down
14 changes: 7 additions & 7 deletions R/write.R
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ write_data2 <- function(
}
}
if (any(dc == openxlsx2_celltype[["short_date"]])) { # Date
numfmt_dt <- getOption("openxlsx2.dateFormat") %||% 14
numfmt_dt <- getOption("openxlsx2.dateFormat", 14)

dim_sel <- get_data_class_dims("short_date")
# message("short_date: ", dim_sel)
Expand All @@ -513,7 +513,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["long_date"]])) {
numfmt_posix <- getOption("openxlsx2.datetimeFormat") %||% 22
numfmt_posix <- getOption("openxlsx2.datetimeFormat", default = 22)

dim_sel <- get_data_class_dims("long_date")
# message("long_date: ", dim_sel)
Expand All @@ -525,7 +525,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["hms_time"]])) {
numfmt_hms <- getOption("openxlsx2.hmsFormat") %||% 21
numfmt_hms <- getOption("openxlsx2.hmsFormat", default = 21)

dim_sel <- get_data_class_dims("hms_time")
# message("hms: ", dim_sel)
Expand All @@ -537,7 +537,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["accounting"]])) { # accounting
numfmt_accounting <- getOption("openxlsx2.accountingFormat") %||% 4
numfmt_accounting <- getOption("openxlsx2.accountingFormat", default = 4)

dim_sel <- get_data_class_dims("accounting")
# message("accounting: ", dim_sel)
Expand All @@ -548,7 +548,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["percentage"]])) { # percentage
numfmt_percentage <- getOption("openxlsx2.percentageFormat") %||% 10
numfmt_percentage <- getOption("openxlsx2.percentageFormat", default = 10)

dim_sel <- get_data_class_dims("percentage")
# message("percentage: ", dim_sel)
Expand All @@ -560,7 +560,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["scientific"]])) {
numfmt_scientific <- getOption("openxlsx2.scientificFormat") %||% 48
numfmt_scientific <- getOption("openxlsx2.scientificFormat", default = 48)

dim_sel <- get_data_class_dims("scientific")
# message("scientific: ", dim_sel)
Expand All @@ -572,7 +572,7 @@ write_data2 <- function(
)
}
if (any(dc == openxlsx2_celltype[["comma"]])) {
numfmt_comma <- getOption("openxlsx2.commaFormat") %||% 3
numfmt_comma <- getOption("openxlsx2.commaFormat", default = 3)

dim_sel <- get_data_class_dims("comma")
# message("comma: ", dim_sel)
Expand Down
4 changes: 2 additions & 2 deletions R/write_xlsx.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ write_xlsx <- function(x, file, as_table = FALSE, ...) {
}

creator <- creator %||%
getOption("openxlsx2.creator") %||%
getOption("openxlsx2.creator", default = Sys.getenv("USERNAME")) %||%
# USERNAME may only be present for windows
Sys.getenv("USERNAME", Sys.getenv("USER"))
Sys.getenv("USER")

#---add_worksheet---#
## sheetName
Expand Down

0 comments on commit a50e2e5

Please sign in to comment.