diff --git a/NEWS.md b/NEWS.md index 3a66b267..73c35fec 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ * Exporting a new dataset `dataset_spec` that contains the Dataset Specification for ADSL. (#179) * Added a check for character variable lengths up to 200 bytes in `xpt_validate()`(#91, #189). +* File name check is moved to strict_checks condition to allow underscores in the file name. Underscores are allowed in xpt but not per FDA requirements. (#126) ## Deprecation and Breaking Changes diff --git a/R/write.R b/R/write.R index c9005471..ebe5e200 100644 --- a/R/write.R +++ b/R/write.R @@ -75,12 +75,12 @@ xportr_write <- function(.df, abort("`.df` file name must be 8 characters or less.") } + checks <- xpt_validate(.df) + if (stringr::str_detect(name, "[^a-zA-Z0-9]")) { - abort("`.df` cannot contain any non-ASCII, symbol or underscore characters.") + checks <- c(checks, "`.df` cannot contain any non-ASCII, symbol or underscore characters.") } - checks <- xpt_validate(.df) - if (length(checks) > 0) { if (!strict_checks) { warn(c("The following validation checks failed:", checks)) diff --git a/tests/testthat/test-write.R b/tests/testthat/test-write.R index 44e4718a..d53c7eb0 100644 --- a/tests/testthat/test-write.R +++ b/tests/testthat/test-write.R @@ -99,6 +99,15 @@ test_that("xportr_write: expect error when file name contains non-ASCII symbols expect_error(xportr_write(data_to_save, tmp)) }) +test_that("xportr_write: expect warning when file name contains underscore and strict_checks = FALSE", { + tmpdir <- tempdir() + tmp <- file.path(tmpdir, "test_.xpt") + + on.exit(unlink(tmpdir)) + + expect_warning(xportr_write(data_to_save, tmp, strict_checks = FALSE)) +}) + test_that("xportr_write: expect error when label contains non-ASCII symbols or special characters", { tmpdir <- tempdir() tmp <- file.path(tmpdir, "xyz.xpt")