Skip to content

Commit

Permalink
Merge pull request #289 from jmbarbone/consistent-options
Browse files Browse the repository at this point in the history
makes `options()` setting consistent
  • Loading branch information
JanMarvin authored Dec 6, 2021
2 parents beec7f3 + 929b15f commit 1fa10d1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 141 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* `setStyles()` accepts `halign="justify"`
([#305](https://github.com/ycphs/openxlsx/issues/305))

## Improvements

* `options()` are more consistently set in functions (see: [#289](https://github.com/ychps/openxlsx/issues/262))

# openxlsx 4.2.4

## Fixes
Expand Down
5 changes: 2 additions & 3 deletions R/conditional_formatting.R
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,8 @@ conditionalFormatting <-
style = NULL,
type = "expression",
...) {
od <- getOption("OutDec")
options("OutDec" = ".")
on.exit(expr = options("OutDec" = od), add = TRUE)
op <- get_set_options()
on.exit(options(op), add = TRUE)

type <- tolower(type)
params <- list(...)
Expand Down
5 changes: 2 additions & 3 deletions R/helperFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@
#' }
#'
makeHyperlinkString <- function(sheet, row = 1, col = 1, text = NULL, file = NULL) {
od <- getOption("OutDec")
options("OutDec" = ".")
on.exit(expr = options("OutDec" = od), add = TRUE)
op <- get_set_options()
on.exit(options(op), add = TRUE)

if (missing(sheet)) {
if (!missing(row) || !missing(col)) warning("Option for col and/or row found, but no sheet was provided.")
Expand Down
5 changes: 2 additions & 3 deletions R/openXL.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
#' writeData(wb, "Cars", x, startCol = 2, startRow = 3, rowNames = TRUE)
#' # openXL(wb)
openXL <- function(file = NULL) {
od <- getOption("OutDec")
options("OutDec" = ".")
on.exit(expr = options("OutDec" = od), add = TRUE)
op <- get_set_options()
on.exit(options(op), add = TRUE)

if (is.null(file)) stop("A file has to be specified.")

Expand Down
4 changes: 1 addition & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ do_call_params <- function(fun, params, ..., .map = FALSE) {
}

# sets temporary options
# returns the current options to decrease line use
# option() returns the original values
get_set_options <- function() {
op <- options()
options(
# increase scipen to avoid writing in scientific
scipen = 200,
OutDec = ".",
digits = 22
)
op
}


Expand Down
Loading

0 comments on commit 1fa10d1

Please sign in to comment.