Skip to content

Commit

Permalink
Add examples to wb_set_col_widths_ext
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Dec 18, 2024
1 parent 68008e6 commit 14f6ba6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 11 additions & 3 deletions R/wb_set_col_widths_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@
#'
#' [wb_set_col_widths_ext()] extends [openxlsx2::wb_set_col_widths()] by making
#' `cols` optional (defaults to all columns) and allows setting columns based on
#' column names.
#' column names (rather than index position alone).
#'
#' @inheritParams openxlsx2::wb_set_col_widths
#' @seealso
#' [openxlsx2::wb_data()], [openxlsx2::col_widths-wb()]
#' @examples
#' wb <- as_wb(mtcars)
#'
#' wb_set_col_widths_ext(wb, cols = "drat")
#'
#' # `cols` is optional
#' wb_set_col_widths_ext(wb)
#'
#' @keywords internal
#' @export
#' @importFrom openxlsx2 wb_data wb_set_col_widths
wb_set_col_widths_ext <- function(wb,
cols = NULL,
widths = "auto",
sheet = current_sheet()) {
cols <- cols %||% seq(ncol(openxlsx2::wb_data(wb, sheet)))
cols <- cols %||% seq(ncol(openxlsx2::wb_data(wb, sheet = sheet)))

if (any(is.na(as.integer(cols)))) {
if (any(is.na(suppressWarnings(as.integer(cols))))) {
cols <- wb_cols_to_index(
wb,
cols = cols,
Expand Down
9 changes: 9 additions & 0 deletions man/wb_set_col_widths_ext.Rd

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

0 comments on commit 14f6ba6

Please sign in to comment.