Skip to content

Commit

Permalink
Merge pull request #165 from spsanderson/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
spsanderson committed Jun 2, 2023
2 parents 66fec50 + 4d1b9d1 commit d3e7610
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# healthyR (development version)

## Breaking Changes
None

## New Features
None

## Minor Fixes and Improvements
1. Fix #153 - Additions to check logic by @alcrosby for `save_to_excel()`

# healthyR 0.2.1

## Breaking Changes
Expand Down
29 changes: 21 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,38 @@
save_to_excel <- function(.data, .file_name) {

# Checks
if(!is.data.frame(.data)){
stop(call. = FALSE, "(.data) is not a data.frame/tibble. Please supply.")
if (!is.data.frame(.data) & !is.list(.data)){
rlang::abort(
message = ".data is not a data.frame/tibble. Please supply",
use_cli_format = TRUE
)
}

if (is.list(.data) & !all(unlist(purrr::map(.data, is.data.frame)))) {
rlang::abort(
message = ".data is a list, but is not a list of data.frames/tibbles.
Please supply a valid list."
)
}

if(is.na(.file_name)){
stop(call. = FALSE, "(.file_name) was not provided. Please supply.")
rlang::abort(
message = ".file_name must be supplied.",
use_cli_format = TRUE
)
}

data_tbl <- tibble::as_tibble(.data)
dl <- .data

# Save Dir
file_path <- utils::choose.dir()

# File Name
file_name <- .file_name
file_date <- base::Sys.Date() %>%
file_date <- base::Sys.Date() |>
stringr::str_replace_all("-","")
file_time <- base::Sys.time() %>%
healthyR::sql_right(5) %>%
file_time <- base::Sys.time() |>
healthyR::sql_right(5) |>
stringr::str_replace_all(":","")
file_name <- base::paste0(
"\\"
Expand All @@ -59,7 +72,7 @@ save_to_excel <- function(.data, .file_name) {

# Save file
writexl::write_xlsx(
x = data_tbl
x = dl
, path = f_pn
)

Expand Down

0 comments on commit d3e7610

Please sign in to comment.