diff --git a/NAMESPACE b/NAMESPACE index 8cc62576..4b953dab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/write.R b/R/write.R index 57367fc2..930671ea 100644 --- a/R/write.R +++ b/R/write.R @@ -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 diff --git a/R/xportr-package.R b/R/xportr-package.R index 7721bdd7..c95edd96 100644 --- a/R/xportr-package.R +++ b/R/xportr-package.R @@ -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"