-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
6 changed files
with
113 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,8 @@ Suggests: | |
lubridate, | ||
tibble, | ||
testthat (>= 3.0.0), | ||
pool | ||
pool, | ||
visR | ||
Enhances: | ||
CirceR, | ||
Capr | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
#' Create an attrition diagram from a generated cohort set | ||
#' | ||
#' @param x A GeneratedCohortSet object | ||
#' @param ... Not used | ||
#' | ||
#' `r lifecycle::badge("experimental")` | ||
#' | ||
#' @return No return value. This function will create one attrition plot for each generated cohort. | ||
#' @export | ||
#' @importFrom visR visr | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' library(CDMConnector) | ||
#' library(dplyr) | ||
#' | ||
#' con <- DBI::dbConnect(duckdb::duckdb(), eunomia_dir()) | ||
#' cdm <- cdm_from_con(con, "main", "main") | ||
#' cohort_set <- read_cohort_set(system.file("cohorts2", package = "CDMConnector")) | ||
#' cdm <- generate_cohort_set(cdm, cohort_set, name = "cohort", overwrite = T) | ||
#' | ||
#' cohort_attrition(cdm$cohort) %>% | ||
#' dplyr::filter(cohort_definition_id == 3) %>% | ||
#' visR::visr() | ||
#' | ||
#' DBI::dbDisconnect(con, shutdown = TRUE) | ||
#' } | ||
#' | ||
visr.omop_attrition <- function(x, ...) { | ||
if (!rlang::is_installed("visR")) cli::cli_abort("Please install the visR package.") | ||
|
||
ids <- unique(x$cohort_definition_id) | ||
if (length(ids) > 1) { | ||
cli::cli_abort("Cannot create attrition diagram because your cohort set has more than one cohort ID ({paste(ids, collapse = ', ')}). \nFirst make sure there is only one cohort_definition_id in the cohort set.") | ||
} | ||
checkmate::assertIntegerish(ids, len = 1, lower = 1, any.missing = FALSE) | ||
|
||
x <- x %>% | ||
dplyr::select(Criteria = reason, `Remaining N` = number_subjects) | ||
|
||
NextMethod(x) | ||
} |
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,23 @@ | ||
|
||
test_that("visR attrition diagram works", { | ||
con <- DBI::dbConnect(duckdb::duckdb(), eunomia_dir()) | ||
cdm <- cdm_from_con(con, "main", "main") | ||
cohort_set <- read_cohort_set(system.file("cohorts2", package = "CDMConnector")) | ||
cdm <- generate_cohort_set(cdm, cohort_set, name = "cohort", overwrite = T) | ||
|
||
expect_error({ | ||
cohort_attrition(cdm$cohort) %>% | ||
visR::visr() | ||
}) | ||
|
||
expect_no_error({ | ||
cohort_attrition(cdm$cohort) %>% | ||
dplyr::filter(cohort_definition_id == 3) %>% | ||
visR::visr() | ||
}) | ||
|
||
DBI::dbDisconnect(con, shutdown = TRUE) | ||
}) | ||
|
||
|
||
|