Skip to content

Commit

Permalink
v0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
edward-burn committed Nov 28, 2024
1 parent c8444d6 commit d336f68
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: CohortSurvival
Title: Estimate Survival from Common Data Model Cohorts
Version: 0.6.0
Version: 0.6.1
Authors@R: c(
person("Edward", "Burn", email = "[email protected]",
role = c("aut", "cre"),
Expand All @@ -27,7 +27,7 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Imports:
CDMConnector (>= 1.3.0),
omopgenerics (>= 0.2.0),
omopgenerics (>= 0.4.0),
checkmate,
cli,
DBI,
Expand All @@ -37,10 +37,8 @@ Imports:
lubridate,
broom,
PatientProfiles,
visOmopResults (>= 0.3.0),
rlang (>= 0.4.11),
survival (>= 3.7.0),
scales,
stringr,
tibble,
tidyr,
Expand All @@ -58,7 +56,9 @@ Suggests:
cmprsk,
duckdb,
gt,
flextable
flextable,
scales,
visOmopResults (>= 0.5.0)
Config/testthat/edition: 3
Config/testthat/parallel: true
VignetteBuilder: knitr
Expand Down
7 changes: 4 additions & 3 deletions R/asSurvivalResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ asSurvivalResult <- function(result) {
cli::cli_abort("result is not a valid `summarised_result` object.")
}
result <- result %>%
visOmopResults::addSettings() %>%
omopgenerics::addSettings(
settingsColumn = c("result_type",omopgenerics::settingsColumns(result))) %>%
dplyr::select(c("cdm_name", "group_name", "group_level", "strata_name",
"strata_level", "variable_name", "variable_level",
"estimate_name", "estimate_type", "estimate_value",
"additional_name", "additional_level", "result_type",
"outcome", "competing_outcome",
"eventgap")) %>%
visOmopResults::splitAdditional() %>%
visOmopResults::splitGroup() %>%
omopgenerics::splitAdditional() %>%
omopgenerics::splitGroup() %>%
dplyr::mutate(estimate_value = as.numeric(.data$estimate_value))

estimates <- result %>%
Expand Down
11 changes: 11 additions & 0 deletions R/deathDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ deathDiagnostics <- function(cdm,
output <- output %>%
dplyr::mutate(
cdm_name = attr(cdm, "cdm_name"),
result_id = 1,
result_type = "death_diagnostics",
package_name = "CohortSurvival",
package_version = as.character(utils::packageVersion("CohortSurvival")),
Expand Down Expand Up @@ -178,6 +179,7 @@ deathDiagnostics <- function(cdm,
output_w <- output_w %>%
dplyr::mutate(
cdm_name = attr(cdm, "cdm_name"),
result_id = 1,
result_type = "death_diagnostics",
package_name = "CohortSurvival",
package_version = as.character(utils::packageVersion("CohortSurvival")),
Expand Down Expand Up @@ -208,5 +210,14 @@ deathDiagnostics <- function(cdm,
}
}

settings <- output %>%
dplyr::select("result_id", "result_type", "package_name", "package_version") %>%
dplyr::distinct()

output <- output %>%
dplyr::select(-c("result_type", "package_name", "package_version"))

output <- omopgenerics::newSummarisedResult(output, settings = settings)

return(output)
}
14 changes: 6 additions & 8 deletions R/estimateSurvival.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ estimateSingleEventSurvival <- function(cdm,
"estimate_type" = "integer",
competing_outcome = "none"
) %>%
visOmopResults::uniteStrata("reason") %>%
visOmopResults::uniteAdditional("reason_id")
omopgenerics::uniteStrata("reason") %>%
omopgenerics::uniteAdditional("reason_id")

if(attrition %>% dplyr::group_by("target_cohort") %>% dplyr::tally() %>% dplyr::pull("n") ==
attrition %>% dplyr::group_by("target_cohort", "cohort_definition_id") %>% dplyr::tally() %>% dplyr::pull("n")) {
Expand Down Expand Up @@ -288,8 +288,7 @@ estimateSingleEventSurvival <- function(cdm,
censor_on_date = .env$censorOnDate,
follow_up_days = .env$followUpDays,
restricted_mean_follow_up = .env$restrictedMeanFollowUp,
minimum_survival_days = .env$minimumSurvivalDays,
min_cell_count = .env$minCellCount
minimum_survival_days = .env$minimumSurvivalDays
)

surv_estimates <- omopgenerics::newSummarisedResult(complete_results,
Expand Down Expand Up @@ -520,8 +519,8 @@ estimateCompetingRiskSurvival <- function(cdm,
"estimate_value" = as.character(.data$estimate_value),
"estimate_type" = "integer"
) %>%
visOmopResults::uniteStrata("reason") %>%
visOmopResults::uniteAdditional("reason_id")
omopgenerics::uniteStrata("reason") %>%
omopgenerics::uniteAdditional("reason_id")

if(attrition %>% dplyr::group_by("target_cohort") %>% dplyr::tally() %>% dplyr::pull("n") ==
attrition %>% dplyr::group_by("target_cohort", "cohort_definition_id") %>% dplyr::tally() %>% dplyr::pull("n")) {
Expand Down Expand Up @@ -621,8 +620,7 @@ estimateCompetingRiskSurvival <- function(cdm,
censor_on_date = .env$censorOnDate,
follow_up_days = .env$followUpDays,
restricted_mean_follow_up = .env$restrictedMeanFollowUp,
minimum_survival_days = .env$minimumSurvivalDays,
min_cell_count = .env$minCellCount
minimum_survival_days = .env$minimumSurvivalDays
)

surv_estimates <- omopgenerics::newSummarisedResult(complete_results,
Expand Down
3 changes: 3 additions & 0 deletions R/plotSurvival.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ plotSurvival <- function(result,
riskTable = FALSE,
riskInterval = 30) {

rlang::check_installed("ggplot2")
rlang::check_installed("scales")

# Missing input checks
omopgenerics::assertNumeric(xlim, min = 1, length = 1, integerish = TRUE, null = TRUE)
if(is.null(xlim)) {xlim <- "Inf"}
Expand Down
24 changes: 14 additions & 10 deletions R/tableSurvival.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ tableSurvival <- function(x,
groupColumn = NULL,
.options = list()){

rlang::check_installed("visOmopResults", version = "0.5.0")

# initial checks
omopgenerics::assertNumeric(times, min = 0, null = TRUE)
omopgenerics::assertCharacter(timeScale, length = 1)
Expand All @@ -65,10 +67,12 @@ tableSurvival <- function(x,
}

# check times in x
x_clean <- x %>% visOmopResults::splitAdditional() %>%
x_clean <- x %>%
dplyr::filter(.data$result_id %in% (omopgenerics::settings(x) %>%
dplyr::filter(grepl("probability", .data$result_type) | grepl("summary", .data$result_type)) %>%
dplyr::pull("result_id")))
dplyr::pull("result_id"))) %>%
omopgenerics::splitAdditional() %>%
dplyr::select(-"reason_id")

if (!is.null(times)) {
times_final <- dplyr::tibble(
Expand Down Expand Up @@ -136,7 +140,7 @@ tableSurvival <- function(x,
bigMark = .options$bigMark
) %>%
visOmopResults::formatEstimateName(
estimateNameFormat =
estimateName =
c(" survival estimate" =
"<estimate> (<estimate_95CI_lower>, <estimate_95CI_upper>)")
) %>%
Expand Down Expand Up @@ -216,9 +220,10 @@ tableSurvival <- function(x,
"Outcome type" = "variable_name",
"Outcome name" = "variable_level"
)
excludeCols = c("time", "reason_id", "reason")
formatEstimateName = c("Restricted mean survival" = "<restricted_mean_survival>")
} else {
excludeCols = c(excludeCols, "variable_name")
excludeCols = c(excludeCols, "variable_name","time", "reason_id", "reason")
renameCols = c("Outcome name" = "variable_level")
formatEstimateName = c("Restricted mean survival (SE)" =
"<restricted_mean_survival> (<restricted_mean_survival_se>)")
Expand All @@ -233,19 +238,18 @@ tableSurvival <- function(x,

# to SR
summary_table <- summary_table %>%
visOmopResults::uniteAdditional() %>%
omopgenerics::uniteAdditional() %>%
dplyr::select(omopgenerics::resultColumns())

summary_table <- visOmopResults::visOmopTable(
summary_table,
formatEstimateName = formatEstimateName,
estimateName = formatEstimateName,
header = header,
split = split,
groupColumn = groupColumn,
type = type,
renameColumns = renameCols,
rename = renameCols,
showMinCellCount = TRUE,
excludeColumns = excludeCols,
hide = excludeCols,
.options = c(.options, list(useFormatOrder = FALSE)) # to keep order set when factoring
)

Expand All @@ -270,7 +274,7 @@ tableSurvival <- function(x,
#'
#'
optionsTableSurvival <- function() {
default <- visOmopResults::optionsVisOmopTable()
default <- visOmopResults::tableOptions()
default <- default[!names(default) %in% c("useFormatOrder", "keepNotFormatted")]
return(default)
}

0 comments on commit d336f68

Please sign in to comment.