Skip to content

Commit

Permalink
move data into tests
Browse files Browse the repository at this point in the history
to avoid changing `lung` for other test files and to make the tests more self-contained
  • Loading branch information
hfrick committed Nov 9, 2023
1 parent 943a61f commit 34052e0
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tests/testthat/test-survival-workflows.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ skip_if_not_installed("tune", minimum_version = "1.1.1.9001")
library(tidymodels)
library(censored)

lung <- lung |>
tidyr::drop_na() |>
dplyr::mutate(surv = Surv(time, status), .keep = "unused")

test_that("can `fit()` a censored workflow with a formula", {
lung <- lung |>
tidyr::drop_na() |>
dplyr::mutate(surv = Surv(time, status), .keep = "unused")

mod <- proportional_hazards(engine = "glmnet", penalty = 0.1)

workflow <- workflow()
Expand All @@ -27,6 +27,10 @@ test_that("can `fit()` a censored workflow with a formula", {
})

test_that("can `fit()` a censored workflow with variables", {
lung <- lung |>
tidyr::drop_na() |>
dplyr::mutate(surv = Surv(time, status), .keep = "unused")

mod <- proportional_hazards(engine = "glmnet", penalty = 0.1)

workflow <- workflow()
Expand All @@ -44,6 +48,10 @@ test_that("can `fit()` a censored workflow with variables", {
})

test_that("can `fit()` a censored workflow with a recipe", {
lung <- lung |>
tidyr::drop_na() |>
dplyr::mutate(surv = Surv(time, status), .keep = "unused")

rec <- recipes::recipe(surv ~ ., lung)

mod <- proportional_hazards(engine = "glmnet", penalty = 0.1)
Expand All @@ -63,6 +71,10 @@ test_that("can `fit()` a censored workflow with a recipe", {
})

test_that("can `predict()` a censored workflow with a formula", {
lung <- lung |>
tidyr::drop_na() |>
dplyr::mutate(surv = Surv(time, status), .keep = "unused")

mod <- proportional_hazards(engine = "glmnet", penalty = 0.1)

workflow <- workflow()
Expand Down Expand Up @@ -93,6 +105,10 @@ test_that("can `predict()` a censored workflow with a formula", {
})

test_that("can `predict()` a censored workflow with a recipe", {
lung <- lung |>
tidyr::drop_na() |>
dplyr::mutate(surv = Surv(time, status), .keep = "unused")

mod <- proportional_hazards(engine = "glmnet", penalty = 0.1)

workflow <- workflow()
Expand Down Expand Up @@ -123,6 +139,10 @@ test_that("can `predict()` a censored workflow with a recipe", {
})

test_that("can `predict()` a censored workflow with a recipe", {
lung <- lung |>
tidyr::drop_na() |>
dplyr::mutate(surv = Surv(time, status), .keep = "unused")

rec <- recipes::recipe(surv ~ ., lung)

mod <- proportional_hazards(engine = "glmnet", penalty = 0.1)
Expand Down

0 comments on commit 34052e0

Please sign in to comment.