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

Fix cran notes #477

Merged
merged 2 commits into from
Jul 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/recheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
workflow_dispatch:
inputs:
which:
type: choice
description: Which dependents to check
options:
- strong
- most

name: Reverse dependency check

jobs:
revdep_check:
name: Reverse check ${{ inputs.which }} dependents
uses: r-devel/recheck/.github/workflows/recheck.yml@v1
with:
which: ${{ inputs.which }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.Rproj.user
.Rhistory
.RData
.DS_Store
src/*.o
src/*.so
src/*.dll
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: openxlsx
Title: Read, Write and Edit xlsx Files
Version: 4.2.5.9001
Date: 2021-12-13
Version: 4.2.5.9002
Date: 2024-07-17
Authors@R:
c(person(given = "Philipp",
family = "Schauberger",
Expand Down Expand Up @@ -61,7 +61,7 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Collate:
'CommentClass.R'
'HyperlinkClass.R'
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2014-2022
YEAR: 2014-2024
COPYRIGHT HOLDER: openxlsx authors
74 changes: 37 additions & 37 deletions R/build_workbook.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#' Build Workbook
#'
#'
#' Build a workbook from a data.frame or named list
#'
#' @details
#' This function can be used as shortcut to create a workbook object from a
#'
#' @details
#' This function can be used as shortcut to create a workbook object from a
#' data.frame or named list. If names are available in the list they will be
#' used as the worksheet names. The parameters in `...` are collected
#' and passed to [writeData()] or [writeDataTable()] to
#' initially create the Workbook objects then appropriate parameters are
#' initially create the Workbook objects then appropriate parameters are
#' passed to [setColWidths()].
#'
#'
#' @param x A data.frame or a (named) list of objects that can be handled by
#' [writeData()] or [writeDataTable()] to write to file
#' @param asTable If `TRUE` will use [writeDataTable()] rather
#' than [writeData()] to write `x` to the file (default:
#' than [writeData()] to write `x` to the file (default:
#' `FALSE`)
#' @param ... Additional arguments passed to [writeData()],
#' @param ... Additional arguments passed to [writeData()],
#' [writeDataTable()], [setColWidths()] (see Optional
#' Parameters)
#' @author Jordan Mark Barbone
#' @returns A Workbook object
#'
#'
#' @details
#' columns of x with class Date or POSIXt are automatically
#' styled as dates and datetimes respectively.
#'
#'
#' @section Optional Parameters:
#'
#'
#' **createWorkbook Parameters**
#' \itemize{
#' \describe{
#' \item{**creator**}{ A string specifying the workbook author}
#' }
#'
#' **addWorksheet Parameters**
#' \itemize{
#' \describe{
#' \item{**sheetName**}{ Name of the worksheet}
#' \item{**gridLines**}{ A logical. If `FALSE`, the worksheet grid lines will be hidden.}
#' \item{**tabColour**}{ Colour of the worksheet tab. A valid colour (belonging to colours())
Expand All @@ -42,7 +42,7 @@
#' }
#'
#' **writeData/writeDataTable Parameters**
#' \itemize{
#' \describe{
#' \item{**startCol**}{ A vector specifying the starting column(s) to write df}
#' \item{**startRow**}{ A vector specifying the starting row(s) to write df}
#' \item{**xy**}{ An alternative to specifying startCol and startRow individually.
Expand All @@ -55,67 +55,67 @@
#' between each column. If "`all`" all cell borders are drawn.}
#' \item{**borderColour**}{ Colour of cell border}
#' \item{**borderStyle**}{ Border line style.}
#' \item{**keepNA**} {If `TRUE`, NA values are converted to #N/A (or `na.string`, if not NULL) in Excel, else NA cells will be empty. Defaults to FALSE.}
#' \item{**na.string**} {If not NULL, and if `keepNA` is `TRUE`, NA values are converted to this string in Excel. Defaults to NULL.}
#' \item{**keepNA**}{If `TRUE`, NA values are converted to #N/A (or `na.string`, if not NULL) in Excel, else NA cells will be empty. Defaults to FALSE.}
#' \item{**na.string**}{If not NULL, and if `keepNA` is `TRUE`, NA values are converted to this string in Excel. Defaults to NULL.}
#' }
#'
#' **freezePane Parameters**
#' \itemize{
#' \item{**firstActiveRow**} {Top row of active region to freeze pane.}
#' \item{**firstActiveCol**} {Furthest left column of active region to freeze pane.}
#' \item{**firstRow**} {If `TRUE`, freezes the first row (equivalent to firstActiveRow = 2)}
#' \item{**firstCol**} {If `TRUE`, freezes the first column (equivalent to firstActiveCol = 2)}
#' \describe{
#' \item{**firstActiveRow**}{Top row of active region to freeze pane.}
#' \item{**firstActiveCol**}{Furthest left column of active region to freeze pane.}
#' \item{**firstRow**}{If `TRUE`, freezes the first row (equivalent to firstActiveRow = 2)}
#' \item{**firstCol**}{If `TRUE`, freezes the first column (equivalent to firstActiveCol = 2)}
#' }
#'
#' **colWidths Parameters**
#' \itemize{
#' \item{**colWidths**} {May be a single value for all columns (or "auto"), or a list of vectors that will be recycled for each sheet (see examples)}
#' \describe{
#' \item{**colWidths**}{May be a single value for all columns (or "auto"), or a list of vectors that will be recycled for each sheet (see examples)}
#' }
#'
#'
#' @examples
#' x <- data.frame(a = 1, b = 2)
#' wb <- buildWorkbook(x)
#'
#'
#' y <- list(a = x, b = x, c = x)
#' buildWorkbook(y, asTable = TRUE)
#' buildWorkbook(y, asTable = TRUE, tableStyle = "TableStyleLight8")
#'
#'
#' @seealso [write.xlsx()]
#'
#'
#' @export

buildWorkbook <- function(x, asTable = FALSE, ...) {
if (!is.logical(asTable)) {
stop("asTable must be a logical.")
}

params <- list(...)
isList <- inherits(x, "list")

if (isList) {
params[["sheetName"]] <- params[["sheetName"]] %||% names(x) %||% paste0("Sheet ", seq_along(x))
}

## create new Workbook object
wb <- do_call_params(createWorkbook, params)

## If a list is supplied write to individual worksheets using names if available
if (isList) {
do_call_params(addWorksheet, params, wb = list(wb), .map = TRUE)
} else {
params[["sheetName"]] <- params[["sheetName"]] %||% "Sheet 1"
do_call_params(addWorksheet, params, wb = wb)
}

params[["sheet"]] <- params[["sheet"]] %||% params[["sheetName"]]

# write Data
if (asTable) {
do_call_params(writeDataTable, params, x = x, wb = list(wb), .map = TRUE)
} else {
do_call_params(writeData, params, x = x, wb = wb, .map = TRUE)
}

do_setColWidths(wb, x, params, isList)
do_call_params(freezePane, params, wb = list(wb), .map = TRUE)
wb
Expand All @@ -126,18 +126,18 @@ do_setColWidths <- function(wb, x, params, isList) {
if (!isList) {
x <- list(x)
}

params[["startCol"]] <- params[["startCol"]] %||% 1
params[["startCol"]] <- rep_len(list(params[["startCol"]]), length.out = length(x))
params[["colWidths"]] <- params[["colWidths"]] %||% ""
params[["colWidths"]] <- rep_len(as.list(params[["colWidths"]]), length.out = length(x))

for (i in seq_along(wb[["worksheets"]])) {
if (identical(params[["colWidths"]][[i]], "auto")) {
setColWidths(
wb,
sheet = i,
cols = seq_along(x[[i]]) + params[["startCol"]][[i]] - 1L,
cols = seq_along(x[[i]]) + params[["startCol"]][[i]] - 1L,
widths = "auto"
)
} else if (!identical(params[["colWidths"]][[i]], "")) {
Expand Down
Loading
Loading