Skip to content

Commit

Permalink
Merge pull request #210 from JanMarvin/176-options
Browse files Browse the repository at this point in the history
176 options
  • Loading branch information
JanMarvin committed May 30, 2022
2 parents 7b2091d + e507a82 commit bba1ec3
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 76 deletions.
51 changes: 0 additions & 51 deletions R/class-workbook.R
Expand Up @@ -1722,9 +1722,6 @@ wbWorkbook <- R6::R6Class(
#' @param fontName fontName
#' @return The `wbWorkbook` object
set_base_font = function(fontSize = 11, fontColour = "black", fontName = "Calibri") {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (fontSize < 0) stop("Invalid fontSize")
fontColour <- validateColour(fontColour)

Expand Down Expand Up @@ -1786,9 +1783,6 @@ wbWorkbook <- R6::R6Class(
#' @param heights heights
#' @return The `wbWorkbook` object, invisibly
set_row_heights = function(sheet, rows, heights) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

sheet <- wb_validate_sheet(self, sheet)
# TODO move to wbWorksheet method
# TODO consider reworking rowHeights
Expand Down Expand Up @@ -1834,11 +1828,7 @@ wbWorkbook <- R6::R6Class(
#' @param rows rows
#' @return The `wbWorkbook` object, invisibly
remove_row_heights = function(sheet, rows) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

sheet <- wb_validate_sheet(self, sheet)

customRows <- as.integer(names(self$rowHeights[[sheet]]))
removeInds <- which(customRows %in% rows)

Expand Down Expand Up @@ -1870,9 +1860,6 @@ wbWorkbook <- R6::R6Class(
#' @param levels levels
#' @return The `wbWorkbook` object, invisibly
group_cols = function(sheet, cols, collapsed = FALSE, levels = NULL) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

sheet <- wb_validate_sheet(self, sheet)

if (length(collapsed) > length(cols)) {
Expand Down Expand Up @@ -1939,9 +1926,6 @@ wbWorkbook <- R6::R6Class(
#' @param cols = cols
#' @returns The `wbWorkbook` object
ungroup_cols = function(sheet, cols) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

sheet <- wb_validate_sheet(self, sheet)

# check if any rows are selected
Expand Down Expand Up @@ -1979,8 +1963,6 @@ wbWorkbook <- R6::R6Class(
#' @return The `wbWorkbook` object, invisibly
remove_col_widths = function(sheet, cols) {
sheet <- wb_validate_sheet(self, sheet)
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (!is.numeric(cols)) {
cols <- col2int(cols)
Expand Down Expand Up @@ -2122,9 +2104,6 @@ wbWorkbook <- R6::R6Class(
#' @param levels levels
#' @return The `wbWorkbook` object, invisibly
group_rows = function(sheet, rows, collapsed = FALSE, levels = NULL) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

sheet <- wb_validate_sheet(self, sheet)

if (length(collapsed) > length(rows)) {
Expand Down Expand Up @@ -2186,9 +2165,6 @@ wbWorkbook <- R6::R6Class(
#' @param rows rows
#' @return The `wbWorkbook` object
ungroup_rows = function(sheet, rows) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

sheet <- wb_validate_sheet(self, sheet)

# check if any rows are selected
Expand Down Expand Up @@ -2433,9 +2409,6 @@ wbWorkbook <- R6::R6Class(
showInputMsg = TRUE,
showErrorMsg = TRUE
) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

## rows and cols
if (!is.numeric(cols)) {
cols <- col2int(cols)
Expand Down Expand Up @@ -2952,8 +2925,6 @@ wbWorkbook <- R6::R6Class(
firstCol = FALSE
) {
# TODO rename to setFreezePanes?
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

# fine to do the validation before the actual check to prevent other errors
sheet <- wb_validate_sheet(self, sheet)
Expand Down Expand Up @@ -3061,9 +3032,6 @@ wbWorkbook <- R6::R6Class(
units = "in",
dpi = 300
) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (!file.exists(file)) {
stop("File does not exist.")
}
Expand Down Expand Up @@ -3214,9 +3182,6 @@ wbWorkbook <- R6::R6Class(
units = "in",
dpi = 300
) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (is.null(dev.list()[[1]])) {
warning("No plot to insert.")
return(self)
Expand Down Expand Up @@ -3695,9 +3660,6 @@ wbWorkbook <- R6::R6Class(
) {
sheet <- wb_validate_sheet(self, sheet)

op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (!is.null(header) && length(header) != 3) {
stop("header must have length 3 where elements correspond to positions: left, center, right.")
}
Expand Down Expand Up @@ -3835,8 +3797,6 @@ wbWorkbook <- R6::R6Class(
#' @param cols cols
#' @returns The `wbWorkbook` object
add_filter = function(sheet, rows, cols) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)
sheet <- wb_validate_sheet(self, sheet)

if (length(rows) != 1) {
Expand Down Expand Up @@ -3871,9 +3831,6 @@ wbWorkbook <- R6::R6Class(
#' @param show show
#' @returns The `wbWorkbook` object
grid_lines = function(sheet, show = FALSE) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

sheet <- wb_validate_sheet(self, sheet)

if (!is.logical(show)) {
Expand Down Expand Up @@ -3911,9 +3868,6 @@ wbWorkbook <- R6::R6Class(
localSheetId = NULL,
overwrite = FALSE
) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

sheet <- wb_validate_sheet(self, sheet)

if (!is.numeric(rows)) {
Expand Down Expand Up @@ -4033,9 +3987,6 @@ wbWorkbook <- R6::R6Class(
#' @param sheet sheet
#' @returns The `wbWorkbook` object
set_sheet_visibility = function(sheet, value) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (length(value) != length(sheet)) {
stop("`value` and `sheet` must be the same length")
}
Expand Down Expand Up @@ -4081,8 +4032,6 @@ wbWorkbook <- R6::R6Class(
#' @param col col
#' @returns The `wbWorkbook` object
add_page_break = function(sheet, row = NULL, col = NULL) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)
sheet <- wb_validate_sheet(self, sheet)
self$worksheets[[sheet]]$add_page_break(row = row, col = col)
self
Expand Down
4 changes: 1 addition & 3 deletions R/conditional_formatting.R
Expand Up @@ -251,7 +251,7 @@
#' rule = "OR($A1=1,$A1=3,$A1=5,$A1=7)"
#' )
#'
wb_conditional_formatting <-
wb_conditional_formatting <-
function(wb,
sheet,
cols,
Expand All @@ -260,8 +260,6 @@ wb_conditional_formatting <-
style = NULL,
type = "expression",
...) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

type <- tolower(type)
params <- list(...)
Expand Down
5 changes: 0 additions & 5 deletions R/converters.R
Expand Up @@ -9,9 +9,6 @@
#' @examples
#' int2col(1:10)
int2col <- function(x) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (!is.numeric(x)) {
stop("x must be numeric.")
}
Expand Down Expand Up @@ -60,8 +57,6 @@ get_cell_refs <- function(cellCoords) {
if (!all(vapply(cellCoords, is_integer_ish, NA))) {
stop("cellCoords must only contain integers", call. = FALSE)
}
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

l <- int2col(unlist(cellCoords[, 2]))
paste0(l, cellCoords[, 1])
Expand Down
3 changes: 0 additions & 3 deletions R/dates.R
Expand Up @@ -52,9 +52,6 @@ convert_date <- function(x, origin = "1900-01-01", ...) {
#' convert_datetime(x, tz = "Australia/Perth")
#' convert_datetime(x, tz = "UTC")
convert_datetime <- function(x, origin = "1900-01-01", ...) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

x <- as.numeric(x)
date <- convert_date(x, origin)

Expand Down
7 changes: 2 additions & 5 deletions R/helperFunctions.R
Expand Up @@ -86,9 +86,6 @@
#' }
#'
create_hyperlink <- function(sheet, row = 1, col = 1, text = NULL, file = NULL) {
# 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 Expand Up @@ -211,7 +208,7 @@ illegalcharsreplace <- c("&amp;", "&quot;", "&apos;", "&lt;", "&gt;", "", "", ""
#' converts & to &amp;
#' @param v some xml string
#' @keywords internal
#' @noRd
#' @noRd
replaceIllegalCharacters <- function(v) {
v <- as.character(v)

Expand All @@ -223,7 +220,7 @@ replaceIllegalCharacters <- function(v) {
#' converts &amp; to &
#' @param v some xml string
#' @keywords internal
#' @noRd
#' @noRd
replaceXMLEntities <- function(v) {
v <- gsub("&amp;", "&", v, fixed = TRUE)
v <- gsub("&quot;", '"', v, fixed = TRUE)
Expand Down
2 changes: 0 additions & 2 deletions R/names.R
Expand Up @@ -23,8 +23,6 @@ names.wbWorkbook <- function(x) {
#' @param value a character vector the same length as `x`
#' @export
`names<-.wbWorkbook` <- function(x, value) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (any(duplicated(tolower(value)))) {
stop("Worksheet names must be unique.")
Expand Down
2 changes: 0 additions & 2 deletions R/utils.R
Expand Up @@ -53,8 +53,6 @@ temp_xlsx <- function(name = "temp_xlsx", macros = FALSE) {
}

openxlsx2_options <- function() {
# op <- openxlsx2_options()
# on.exit(options(op), add = TRUE)
options(
# increase scipen to avoid writing in scientific
scipen = 200,
Expand Down
2 changes: 0 additions & 2 deletions R/wb_styles.R
Expand Up @@ -790,8 +790,6 @@ create_dxfs_style <- function(
text_italic = NULL,
text_underline = NULL # "true" or "double"
) {
op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

if (is.null(text_bold)) text_bold = ""
if (is.null(text_strike)) text_strike = ""
Expand Down
6 changes: 3 additions & 3 deletions R/write.R
Expand Up @@ -605,6 +605,9 @@ write_data_table <- function(
data_table = FALSE
) {

op <- openxlsx2_options()
on.exit(op, add = TRUE)

## Input validating
assert_workbook(wb)
assert_class(colNames, "logical")
Expand All @@ -625,9 +628,6 @@ write_data_table <- function(

if (wb$isChartSheet[[sheet]]) stop("Cannot write to chart sheet.")

op <- openxlsx2_options()
on.exit(options(op), add = TRUE)

## All input conversions/validations
if (!is.null(xy)) {
if (length(xy) != 2) {
Expand Down

0 comments on commit bba1ec3

Please sign in to comment.