diff --git a/DESCRIPTION b/DESCRIPTION index a15b95a..672420c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: vpc Title: Create Visual Predictive Checks -Version: 1.3.6 -Date: 2026-11-12 +Version: 1.3.7 +Date: 2026-11-14 Authors@R: c( person("Ron", "Keizer", email="ron@insight-rx.com", role=c("aut", "cre")), diff --git a/NEWS.md b/NEWS.md index 43c059c..ffcc613 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# vpc 1.3.7 +- `vpc_tte()` with `rtte = TRUE` and `rtte_calc_diff = FALSE` or + `rtte_conditional = FALSE` no longer fails with "`time` must be a vector, + not a function" when the data have no column named `t` (#128). Censoring + marks are now placed at the original (absolute) time, stored internally + before any conversion to relative times. + # vpc 1.3.6 - Bins can now be determined per stratum (#11). With `bin_by_strata = TRUE` in `vpc()` and `vpc_cens()`, automatic binning methods are applied to the data diff --git a/R/format_vpc_input_data.R b/R/format_vpc_input_data.R index 262ce5d..8582d4f 100644 --- a/R/format_vpc_input_data.R +++ b/R/format_vpc_input_data.R @@ -149,6 +149,11 @@ format_vpc_input_data_tte <- function(dat, cols, stratify, rtte, rtte_calc_diff, dat[dat$cens == 1,]$dv <- 0 } dat$time <- as.num(dat$idv) + if (rtte) { + # keep the original (absolute) time, used e.g. for plotting censoring + # marks when times are recalculated to relative times between events + dat$time_abs <- dat$time + } if (what == "observed") { # set sim to simplify code below dat$sim <- 1 diff --git a/R/vpc_tte.R b/R/vpc_tte.R index f911e60..41a3b16 100644 --- a/R/vpc_tte.R +++ b/R/vpc_tte.R @@ -265,7 +265,7 @@ vpc_tte <- function(sim = NULL, if(rtte) { if(!rtte_conditional || !rtte_calc_diff) { cens_dat <- cens_dat %>% - dplyr::mutate(time = t) + dplyr::mutate(time = .data$time_abs) } } cens_dat <- cens_dat %>% diff --git a/tests/testthat/test-vpc_tte.R b/tests/testthat/test-vpc_tte.R index 69951d1..7f62804 100644 --- a/tests/testthat/test-vpc_tte.R +++ b/tests/testthat/test-vpc_tte.R @@ -103,3 +103,29 @@ test_that("vpc_tte() keeps positional argument order (ci_sim appended last)", { expect_s3_class(pl, "ggplot") expect_equal(pl$labels$x, "Positional time label") }) + +test_that("vpc_tte(rtte = TRUE) works without a `t` column (#128)", { + obs <- data.frame(id = rep(1:2, each = 2), time = c(3, 10, 4, 8), dv = c(1, 0, 1, 0)) + sim <- rbind(cbind(obs, sim = 1), cbind(obs, sim = 2)) + for (args in list( + list(rtte_calc_diff = FALSE, rtte_conditional = TRUE), + list(rtte_calc_diff = TRUE, rtte_conditional = FALSE), + list(rtte_calc_diff = FALSE, rtte_conditional = FALSE) + )) { + db <- suppressWarnings( + vpc_tte(sim = sim, obs = obs, rtte = TRUE, + rtte_calc_diff = args$rtte_calc_diff, + rtte_conditional = args$rtte_conditional, + sim_cols = list(sim = "sim"), vpcdb = TRUE) + ) + # censoring marks at the original (absolute) times + expect_equal(sort(db$cens_dat$time), c(8, 10)) + pl <- suppressWarnings( + vpc_tte(sim = sim, obs = obs, rtte = TRUE, + rtte_calc_diff = args$rtte_calc_diff, + rtte_conditional = args$rtte_conditional, + sim_cols = list(sim = "sim")) + ) + expect_s3_class(pl, "ggplot") + } +})