Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update summariseTemporalSymmetry validation fun #289

Merged
merged 1 commit into from
Nov 28, 2024
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
31 changes: 0 additions & 31 deletions R/inputValidation.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,37 +92,6 @@ checkInputSummariseSequenceRatios <- function(cohort,
checkmate::reportAssertions(collection = errorMessage)
}

checkInputSummariseTemporalSymmetry <- function(cohort,
cohortId,
timescale,
minCellCount) {

# Check cdm objects, writing schema and index/marker tables
cdm <- omopgenerics::cdmReference(cohort)
checkCdm(cdm)

cohort_row <- cohort |> dplyr::tally() |> dplyr::pull()
if (cohort_row <=0){
cli::cli_abort("Aborted! The cohort has no rows, please revisit the cohort")
}

checkCohortIds(cohort = cohort,
cohortId = cohortId,
errorMessage = errorMessage)

# Check the rest of inputs
errorMessage <- checkmate::makeAssertCollection()

# Check minCellCount
checkMinCellCount(minCellCount, errorMessage)

# Check timescale
checkTimeScale(timescale, errorMessage)

# Report errors
checkmate::reportAssertions(collection = errorMessage)
}

checkSequenceSymmetry <- function(result) {
omopgenerics::newSummarisedResult(result)
}
Expand Down
17 changes: 13 additions & 4 deletions R/summariseTemporalSymmetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,18 @@ summariseTemporalSymmetry <- function(cohort,
timescale = "month",
minCellCount = 5) {
# checks
checkInputSummariseTemporalSymmetry(cohort = cohort,
cohortId = cohortId,
timescale = timescale,
minCellCount = minCellCount)
cdm <- omopgenerics::cdmReference(cohort)
cdm <- omopgenerics::validateCdmArgument(cdm = cdm)
cohortId <- omopgenerics::validateCohortIdArgument({{cohortId}}, cohort)
omopgenerics::assertChoice(timescale,
choices = c("day", "week","month", "year"),
length = 1)
omopgenerics::assertNumeric(minCellCount,
min = 0,
max = 99999999,
length = 1)

# pulling out data
index_names <- attr(cohort, "cohort_set") |>
dplyr::select("cohort_definition_id", "index_name", "index_id", "marker_id")
marker_names <- attr(cohort, "cohort_set") |>
Expand All @@ -47,6 +54,7 @@ summariseTemporalSymmetry <- function(cohort,
settings <- c("cohort_date_range", "days_prior_observation", "washout_window", "index_marker_gap",
"combination_window", "moving_average_restriction", "timescale")

# computing the output
output <- cohort %>%
dplyr::mutate(time = as.numeric(!!CDMConnector::datediff(
"index_date", "marker_date", interval = timescale))) |>
Expand Down Expand Up @@ -107,6 +115,7 @@ summariseTemporalSymmetry <- function(cohort,
package_version = as.character(utils::packageVersion("CohortSymmetry")),
timescale = .env$timescale)

# new summarise result
output_sum <- output_sum |>
dplyr::left_join(setting, by = c("cdm_name", "days_prior_observation", "washout_window",
"index_marker_gap", "combination_window", "timescale")) |>
Expand Down
17 changes: 0 additions & 17 deletions tests/testthat/test-summariseTemporalSymmetry.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,3 @@ test_that("input validation",{
CDMConnector::cdmDisconnect(cdm = cdm)

})

test_that("edge case",{
skip_on_cran()
cdm <- mockCohortSymmetry()
cdm <- generateSequenceCohortSet(
cdm = cdm,
name = "joined_cohorts",
indexTable = "cohort_1",
markerTable = "cohort_2",
combinationWindow = c(10, 11)
)

expect_error(
result <- summariseTemporalSymmetry(cohort = cdm$joined_cohorts)
)

})
Loading