Skip to content

Commit

Permalink
use readxl to load df from xls file
Browse files Browse the repository at this point in the history
  • Loading branch information
hongooi73 committed Feb 14, 2024
1 parent ae8538e commit 5fe5f10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Suggests:
testthat,
blastula,
emayili,
readr
readr,
readxl
Roxygen: list(markdown=TRUE, r6=FALSE)
RoxygenNote: 7.2.1
13 changes: 13 additions & 0 deletions R/ms_drive_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,19 @@ public=list(
{
private$assert_is_file()
ext <- tolower(tools::file_ext(self$properties$name))
if(!(ext %in% c("csv", "csv2", "xls", "xlsx")))
stop("Data frame can only be loaded from a CSV or Excel file")

if(ext %in% c("xls", "xlsx"))
{
if(!requireNamespace("readxl"))
stop("The readxl package must be installed to load an Excel spreadsheet")
infile <- paste0(tempfile(), ".", ext)
self$download(dest=infile)
on.exit(unlink(infile, force=TRUE))
return(readxl::read_excel(infile, ...))
}

if(is.null(delim))
{
delim <- if(ext == "csv") "," else if(ext == "csv2") ";" else "\t"
Expand Down

0 comments on commit 5fe5f10

Please sign in to comment.