Skip to content

Commit

Permalink
test no error for variable end with _temp(#2012)
Browse files Browse the repository at this point in the history
  • Loading branch information
ynsec37 committed Jul 17, 2023
1 parent 4c6d37d commit 28382b1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions R/derive_vars_dy.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ derive_vars_dy <- function(dataset,
mutate(
across(
.cols = vars2chr(unname(source_vars)),
.fns = ~compute_duration(start_date = !!reference_date, end_date = .x),
.fns = ~ compute_duration(start_date = !!reference_date, end_date = .x),
.names = "{dy_vars}"
))
)
)
}
32 changes: 32 additions & 0 deletions tests/testthat/test-derive_vars_dy.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,35 @@ test_that("derive_vars_dy Test 9: Single named --DT input when ref date is --DTM
keys = c("STUDYID", "USUBJID")
)
})

## Test 10: no error if input with variable end with `_temp` ----
test_that("derive_vars_dy Test 10: no error if input with variable end with `_temp`", {
datain <- tibble::tribble(
~STUDYID, ~USUBJID, ~TRTSDTM, ~ASTDT, ~test_temp,
"TEST01", "PAT01", "2014-01-17T23:59:59", "2014-01-18", "test"
) %>%
mutate(
TRTSDTM = lubridate::as_datetime(TRTSDTM),
ASTDT = lubridate::ymd(ASTDT)
)

expected_output <- tibble::tribble(
~STUDYID, ~USUBJID, ~TRTSDTM, ~ASTDT, ~test_temp, ~ASTDY,
"TEST01", "PAT01", "2014-01-17T23:59:59", "2014-01-18", "test", 2
) %>%
mutate(
TRTSDTM = lubridate::as_datetime(TRTSDTM),
ASTDT = lubridate::ymd(ASTDT)
)

actual_output <- derive_vars_dy(datain,
reference_date = TRTSDTM,
source_vars = exprs(ASTDT)
)

expect_dfs_equal(
expected_output,
actual_output,
keys = c("STUDYID", "USUBJID")
)
})

0 comments on commit 28382b1

Please sign in to comment.