Skip to content
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ time variables. (#298)

## Bug Fixes
* Fixed verbose option bugs in `xportr_format()` and added missing `xportr.order_verbose` option (#318)
* Fixed `xportr_format()` to exclude variables ending with `ELTM` from the date/time format check, as these indicate time relative to an anchor time in SDTM or ADaM (#293)

## Breaking Changes and Deprecation

Expand Down
8 changes: 4 additions & 4 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#' producing a warning, or 'message' producing a message. A value of 'none'
#' will not output any messages.
#'
#' 1) If the variable has a suffix of `DT`, `DTM`, `TM` (indicating a
#' numeric date/time variable) then a message will be shown if there is
#' no format associated with it.
#' 1) If the variable has a suffix of `DT`, `DTM`, or `TM` excluding `ELTM`
#' (indicating a numeric date/time variable) , then a message will be shown
#' if there is no format associated with it.
#'
#' 2) If a variable is character then a message will be shown if there is
#' no `$` prefix in the associated format.
Expand Down Expand Up @@ -174,7 +174,7 @@ check_formats <- function(.df, format, verbose) {

# check that any variables ending DT, DTM, TM have a format
if (identical(format_sas, "")) {
if (isTRUE(grepl("(DT|DTM|TM)$", colnames(.df)[i]))) {
if (isTRUE(grepl("(DT|DTM|TM)$", colnames(.df)[i])) && !grepl("ELTM$", colnames(.df)[i])) {
message <- glue(
"(xportr::xportr_format) {encode_vars(colnames(.df)[i])} is expected to have a format but does not."
)
Expand Down
6 changes: 3 additions & 3 deletions man/xportr_format.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests/testthat/test-format.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ test_that("xportr_format Test 5: Variable ending in TM should produce an error i
)
})

## Test 5: Variable ending in TM should not produce an error if the class is character (SDTM) ----
test_that("xportr_format Test 5: Variable ending in TM should not produce an error if the class is character (SDTM)", {
adsl <- data.frame(
USUBJID = c(1001, 1002, 1003),
EXELTM = c("1", "1", "2")
)

metadata <- data.frame(
dataset = c("adsl", "adsl"),
variable = c("USUBJID", "EXELTM"),
format = c(NA, NA)
)

expect_no_message(
xportr_format(adsl, metadata, verbose = "stop")
)
})

## Test 6: Variable ending in DTM should produce a warning if no format ----
test_that("xportr_format Test 6: Variable ending in DTM should produce a warning if no format", {
adsl <- data.frame(
Expand Down