Skip to content

Commit

Permalink
Merge pull request #208 from atorus-research/126_filename_checks
Browse files Browse the repository at this point in the history
Closes #126 - Update check for filename to allow underscore
  • Loading branch information
bms63 authored Jan 16, 2024
2 parents 6fc3451 + 2e592e0 commit edae84f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions R/write.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit edae84f

Please sign in to comment.