Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #165

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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