r-lib / vctrs

Generic programming with typed R vectors

Home Page:https://vctrs.r-lib.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ggsurvplot internal error

mmaughan0 opened this issue · comments

Reprex code:
library(heemod)
library(flexsurv)
library(rgho)
library(survival)
library(ggplot2)

install.packages("survival")
install.packages("survminer")
install.packages("dpylr")

##par_mod <- define_parameters(
##age_base = 30*365,##cycle in this model is 1 day
##age_cycle = model_time + age_base)

###put more comments in code##

par_mod <- define_parameters(

p_death_disease_base = compute_surv(
fit_death_disease_base,
time = state_time,
km_limit = 14))

par_mod <- modify(
par_mod,

p_death_disease_mAb = compute_surv(
fit_death_disease_mAb,
time = state_time,
km_limit = 14))

tab_surv_base <- structure(list(time = c(1,1,2,3,5,5,6,6,7,7,8,9,
10, 14, 14 ), status = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L)), .Names = c("time", "status"), row.names = c(NA, -14L), class = "data.frame")

ggsurvplot(tab_surv_base)

Error:
Error in vec_slice():
! Column time (size 15) must match the data frame (size 14).
ℹ In file slice.c at line 188.
ℹ Install the winch package to get additional debugging info the next time you get this error.
ℹ This is an internal error that was detected in the vctrs package.
Please report it at https://github.com/r-lib/vctrs/issues with a reprex and the full backtrace.
Backtrace:

  1. ├─survminer::ggsurvplot(tab_surv_base)
  2. │ ├─base::do.call(ggsurvplot_df, opts_df)
  3. │ └─survminer (local) <fn>(...)
  4. │ └─survminer:::.connect2origin(df)
  5. │ └─d %>% dplyr::distinct(strata, .keep_all = TRUE)
  6. ├─dplyr::distinct(., strata, .keep_all = TRUE)
  7. ├─dplyr:::distinct.data.frame(., strata, .keep_all = TRUE)
  8. │ ├─dplyr::dplyr_row_slice(out, loc)
  9. │ └─dplyr:::dplyr_row_slice.data.frame(out, loc)
  10. │ ├─dplyr::dplyr_reconstruct(vec_slice(data, i), data)
  11. │ │ └─dplyr:::dplyr_new_data_frame(data)
  12. │ │ ├─row.names %||% .row_names_info(x, type = 0L)
  13. │ │ └─base::.row_names_info(x, type = 0L)
  14. │ └─vctrs::vec_slice(data, i)
  15. └─rlang:::stop_internal_c_lib(...)
  16. └─rlang::abort(message, call = call, .internal = TRUE, .frame = frame)

In tab_surv_base, your time column has 15 elements, but you've declared the number of rows as 14.

This is an invalid / corrupt data frame, and there is nothing vctrs can do to support that. You'll need to fix that one on your end, or, if this data object came from another package, report the issue upstream to them