Skip to content

Commit b68add2

Browse files
committed
updates to survfit models
1 parent 03f195d commit b68add2

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

R/ard_survival_survfit.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#' @param y (`Surv` or `string`)\cr
2727
#' an object of class `Surv` created using [survival::Surv()]. This object will be passed as the left-hand side of
2828
#' the formula constructed and passed to [survival::survfit()]. This object can also be passed as a string.
29-
#' @param variables (`character`)\cr
29+
#' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr
3030
#' stratification variables to be passed as the right-hand side of the formula constructed and passed to
31-
#' [survival::survfit()].
31+
#' [survival::survfit()]. Use `variables=NULL` for an unstratified model, e.g. `Surv() ~ 1`.
3232
#' @param method.args (named `list`)\cr
3333
#' named list of arguments that will be passed to [survival::survfit()].
3434
#' @inheritParams rlang::args_dots_empty
@@ -172,7 +172,7 @@ ard_survival_survfit.data.frame <- function(x, y, variables,
172172
# check/process inputs -------------------------------------------------------
173173
check_not_missing(y)
174174
check_not_missing(variables)
175-
check_class(variables, "character")
175+
cards::process_selectors(x, variables = {{ variables }})
176176

177177
# process outcome as string --------------------------------------------------
178178
y <- enquo(y)
@@ -182,9 +182,15 @@ ard_survival_survfit.data.frame <- function(x, y, variables,
182182
else y <- expr_deparse(quo_get_expr(y)) # styler: off
183183

184184
# build model ----------------------------------------------------------------
185+
survfit_formula <-
186+
case_switch(
187+
!is_empty(variables) ~ stats::reformulate(termlabels = bt(variables), response = y),
188+
.default = stats::reformulate(termlabels = "1", response = y)
189+
)
190+
185191
construct_model(
186192
data = x,
187-
formula = stats::reformulate(termlabels = bt(variables), response = y),
193+
formula = survfit_formula,
188194
method = "survfit",
189195
package = "survival",
190196
method.args = {{ method.args }}

man/ard_survival_survfit.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/construction_helpers.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-ard_survival_survfit.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,16 @@ test_that("ard_survival_survfit.data.frame() works as expected", {
259259
class(mtcars$vs)
260260
)
261261
})
262+
263+
test_that("ard_survival_survfit.data.frame(variables=NULL) for unstratified model", {
264+
expect_equal(
265+
cards::ADTTE |>
266+
ard_survival_survfit(
267+
y = ggsurvfit::Surv_CNSR(AVAL, CNSR),
268+
variables = NULL,
269+
times = 90
270+
),
271+
survival::survfit(ggsurvfit::Surv_CNSR() ~ 1, data = cards::ADTTE) |>
272+
ard_survival_survfit(times = 90)
273+
)
274+
})

0 commit comments

Comments
 (0)