Skip to content

Commit

Permalink
DS-2858: Fix writing xlsx files to Cloud Drive
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmclean committed Dec 12, 2022
1 parent fd65b74 commit 7711dfb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: flipAPI
Type: Package
Title: Web APIs tools
Version: 1.3.2
Version: 1.3.3
Author: Displayr <opensource@displayr.com>
Maintainer: Displayr <opensource@displayr.com>
Description: Functions to extract data and interact with web APIs.
Expand Down
12 changes: 8 additions & 4 deletions R/DataMart.R
Expand Up @@ -258,6 +258,9 @@ QLoadData <- function(filename, company.token = NA, ...)
#'
#' Saving to .gif file is only supported for \code{"gganim"} objects created using
#' \code{gganimate}.
#'
#' When saving to .xlsx file, \code{object} is first coerced to a data.frame using
#' \code{\link{as.data.frame}}.
#' @export
QSaveData <- function(object, filename, ...)
{
Expand All @@ -278,7 +281,7 @@ QSaveData <- function(object, filename, ...)
stop("To save as a Powerpoint pptx file, the input must be created with ",
"officer::read_pptx()")
else if (type == "xlsx")
openxlsx::write.xlsx(object, tmpfile, ...)
openxlsx::write.xlsx(as.data.frame(object, check.names = FALSE), tmpfile, ...)
else if (type == "gif" && inherits(object, c("gganim", "gif_image")))
anim_save(tmpfile, object, ...)
else if (type == "gif")
Expand Down Expand Up @@ -311,10 +314,11 @@ QSaveData <- function(object, filename, ...)
paste0(" > QLoadData('", filename, "')"),
sep = "\n")
else
msg <- paste0("Object uploaded to Displayr Cloud Drive. To re-import select ",
"Image > Displayr Cloud Drive.")
msg <- paste0("Object uploaded to Displayr Cloud Drive. To re-import select:\n ",
" Image > Displayr Cloud Drive\n",
"then select ", sQuote(filename), " from the dropdown menu.")
message(msg)
invisible()
invisible(msg)
}

qSaveImage <- function(filename)
Expand Down
3 changes: 3 additions & 0 deletions man/QSaveData.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-datamart.R
Expand Up @@ -22,7 +22,7 @@ test_that("SaveData/LoadData", {
# XLSX
expect_invisible(QSaveData(mtcars, "mtcars.xlsx"))
expect_true(QFileExists("mtcars.xlsx"))
expect_error(QLoadData("mtcars.xlsx"), NA)
expect_equal(dim(QLoadData("mtcars.xlsx")), dim(mtcars))

# GIF
library(gganimate)
Expand Down

0 comments on commit 7711dfb

Please sign in to comment.