Skip to content

Commit

Permalink
feat: checkmate support in write
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Nov 23, 2023
1 parent c1f5d45 commit 7ac63d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ importFrom(checkmate,assert_character)
importFrom(checkmate,assert_choice)
importFrom(checkmate,assert_data_frame)
importFrom(checkmate,assert_integer)
importFrom(checkmate,assert_logical)
importFrom(checkmate,assert_string)
importFrom(checkmate,check_data_frame)
importFrom(checkmate,check_r6)
Expand Down
15 changes: 8 additions & 7 deletions R/write.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,26 @@
#' )
#'
xportr_write <- function(.df, path, label = NULL, strict_checks = FALSE) {
assert_data_frame(.df)
assert_string(path)
assert_string(label, null.ok = TRUE, max.chars = 40)
assert_logical(strict_checks)

path <- normalizePath(path, mustWork = FALSE)

name <- tools::file_path_sans_ext(basename(path))

if (nchar(name) > 8) {
abort("`.df` file name must be 8 characters or less.")
abort("Assertion on file name from `path` failed: Must be 8 characters or less.")
}

if (stringr::str_detect(name, "[^a-zA-Z0-9]")) {
abort("`.df` cannot contain any non-ASCII, symbol or underscore characters.")
abort("Assertion on file name from `path` failed: Must not contain any non-ASCII, symbol or underscore characters.")
}

if (!is.null(label)) {
if (nchar(label) > 40) {
abort("`label` must be 40 characters or less.")
}

if (stringr::str_detect(label, "[^[:ascii:]]")) {
abort("`label` cannot contain any non-ASCII, symbol or special characters.")
abort("Assertion on `label` failed: Must not contain any non-ASCII, symbol or special characters.")
}

attr(.df, "label") <- label
Expand Down
1 change: 1 addition & 0 deletions R/xportr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
#' @importFrom magrittr %>% extract2
#' @importFrom checkmate assert assert_string assert_choice assert_data_frame
#' check_r6 check_data_frame test_string test_r6 assert_character assert_integer
#' assert_logical
#'
"_PACKAGE"

Expand Down

0 comments on commit 7ac63d2

Please sign in to comment.