Skip to content

Commit

Permalink
feat: Add options to use openxlsx2 to write_sharepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Nov 8, 2023
1 parent 268ccd5 commit c4df2d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Suggests:
fs,
knitr,
officer,
openxlsx2,
rappdirs,
readr,
readxl,
Expand Down
8 changes: 6 additions & 2 deletions R/write_sharepoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#' using:
#'
#' - [sf::write_sf()] if x is an `sf` object
#' - [readr::write_csv()] if x is a `data.frame`
#' - [readr::write_csv()] if x is a `data.frame` and file does not include a xlsx extension
#' - [openxlsx2::write_xlsx()] if x is a `data.frame` file does include a xlsx extension
#' - The [print()] method from `{officer}` if x is a `rdocx`, `rpptx`, or `rxlsx` object
#' - [readr::write_rds()] if x is any other class
#'
Expand Down Expand Up @@ -46,9 +47,12 @@ write_sharepoint <- function(x,
if (inherits(x, "sf")) {
check_installed("sf", call = call)
sf::write_sf(x, dsn = file, ...)
} else if (inherits(x, "data.frame")) {
} else if (inherits(x, "data.frame") && !stringr::str_detect(file, ".xlsx$")) {
check_installed("readr", call = call)
readr::write_csv(x, file = file, ...)
} else if (inherits(x, "data.frame") && stringr::str_detect(file, ".xlsx$")) {
check_installed("openxlsx2", call = call)
openxlsx2::write_xlsx(x, file = file, ...)
} else if (inherits(x, c("rdocx", "rpptx", "rxslx"))) {
check_installed("officer", call = call)
print(x, target = file, ...)
Expand Down
3 changes: 2 additions & 1 deletion man/write_sharepoint.Rd

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

0 comments on commit c4df2d0

Please sign in to comment.