generated from insightsengineering/r.pkg.template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d13b70
commit b990b8c
Showing
8 changed files
with
82 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#' Assertion of Adverse Event Data | ||
#' | ||
#' Custom assertion to check adverse event data sets. | ||
#' | ||
#' @param data `data.frame` to be checked for `time_to_event` and `type_of_event` columns. | ||
#' | ||
#' @return None. | ||
#' | ||
#' @keywords internal | ||
assert_ae_data <- function(data) { | ||
assert_data_frame(data, any.missing = FALSE, min.rows = 1, min.cols = 2) | ||
assert_numeric(data$time_to_event, lower = 0, finite = TRUE) | ||
assert_integerish(data$type_of_event, any.missing = FALSE) | ||
assert_subset(data$type_of_event, c(0, 1, 2, 3)) | ||
invisible() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# assert_ae_data ---- | ||
|
||
test_that("assert_ae_data passes as expected", { | ||
data <- data.frame( | ||
time_to_event = c(12.0, 1.2, 0.3), | ||
type_of_event = c(1L, 2L, 0L) | ||
) | ||
result <- expect_silent(assert_ae_data(data)) | ||
expected <- NULL | ||
expect_identical(result, expected) | ||
}) | ||
|
||
test_that("assert_ae_data fails as expected", { | ||
expect_error( | ||
assert_ae_data( | ||
data.frame(bla = 0, bli = 1) | ||
), | ||
"'data$time_to_event' failed", | ||
fixed = TRUE | ||
) | ||
expect_error( | ||
assert_ae_data( | ||
data.frame(time_to_event = -1.3, bli = 1) | ||
), | ||
"Element 1 is not >= 0", | ||
fixed = TRUE | ||
) | ||
expect_error( | ||
assert_ae_data( | ||
data.frame(time_to_event = 0, bli = 1) | ||
), | ||
"'data$type_of_event' failed", | ||
fixed = TRUE | ||
) | ||
expect_error( | ||
assert_ae_data( | ||
data.frame(time_to_event = 0, type_of_event = 4L) | ||
), | ||
"Must be a subset of {'0','1','2','3'}", | ||
fixed = TRUE | ||
) | ||
}) |