Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if argument 'data' is not provided. #235

Closed
dnzmarcio opened this issue Jun 23, 2017 · 4 comments
Closed

Error if argument 'data' is not provided. #235

dnzmarcio opened this issue Jun 23, 2017 · 4 comments

Comments

@dnzmarcio
Copy link

Expected behavior

The function .get_data would extract data from the model fit if the argument 'data' is not provided.

Actual behavior

The function .get_data returns NULL.

Steps to reproduce the problem

library(survminer)
library(survival)
fit <- survfit(Surv(ovarian$futime, ovarian$fustat) ~ 1)
ggsurvplot(fit)
fit <- survfit(Surv(ovarian$futime, ovarian$fustat) ~ 1, data = ovarian)
ggsurvplot(fit)

session_info()

# please paste here the result of
devtools::session_info()
Session info -------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.1 (2016-06-21)
 system   x86_64, mingw32             
 ui       RStudio (1.0.136)           
 language (EN)                        
 collate  English_United States.1252  
 tz       America/Los_Angeles         
 date     2017-06-23                  

Packages -----------------------------------------------------------------------------------------------------
 package    * version   date       source                               
 assertthat   0.1       2013-12-06 CRAN (R 3.3.1)                       
 base       * 3.3.1     2016-06-21 local                                
 bindr        0.1       2016-11-13 CRAN (R 3.3.3)                       
 bindrcpp     0.2       2017-06-17 CRAN (R 3.3.3)                       
 broom        0.4.2     2017-02-13 CRAN (R 3.3.3)                       
 chron        2.3-50    2017-02-20 CRAN (R 3.3.3)                       
 cmprsk       2.2-7     2014-06-17 CRAN (R 3.3.3)                       
 colorspace   1.2-6     2015-03-11 CRAN (R 3.3.1)                       
 data.table   1.9.6     2015-09-19 CRAN (R 3.3.1)                       
 datasets   * 3.3.1     2016-06-21 local                                
 devtools     1.13.1    2017-05-13 CRAN (R 3.3.3)                       
 digest       0.6.10    2016-08-02 CRAN (R 3.3.1)                       
 dplyr        0.7.1     2017-06-22 CRAN (R 3.3.1)                       
 foreign      0.8-67    2016-09-13 CRAN (R 3.3.1)                       
 ggplot2    * 2.2.1     2016-12-30 CRAN (R 3.3.3)                       
 ggpubr     * 0.1.3     2017-06-06 CRAN (R 3.3.3)                       
 glue         1.1.0     2017-06-13 CRAN (R 3.3.3)                       
 graphics   * 3.3.1     2016-06-21 local                                
 grDevices  * 3.3.1     2016-06-21 local                                
 grid         3.3.1     2016-06-21 local                                
 gridExtra    2.2.1     2016-02-29 CRAN (R 3.3.1)                       
 gtable       0.2.0     2016-02-26 CRAN (R 3.3.1)                       
 km.ci        0.5-2     2009-08-30 CRAN (R 3.3.2)                       
 KMsurv       0.1-5     2012-12-03 CRAN (R 3.3.2)                       
 knitr        1.14      2016-08-13 CRAN (R 3.3.1)                       
 labeling     0.3       2014-08-23 CRAN (R 3.3.0)                       
 lattice      0.20-34   2016-09-06 CRAN (R 3.3.1)                       
 lazyeval     0.2.0     2016-06-12 CRAN (R 3.3.1)                       
 magrittr   * 1.5       2014-11-22 CRAN (R 3.3.1)                       
 Matrix       1.2-7.1   2016-09-01 CRAN (R 3.3.1)                       
 memoise      1.0.0     2016-01-29 CRAN (R 3.3.1)                       
 methods    * 3.3.1     2016-06-21 local                                
 mnormt       1.5-4     2016-03-09 CRAN (R 3.3.0)                       
 munsell      0.4.3     2016-02-13 CRAN (R 3.3.1)                       
 nlme         3.1-128   2016-05-10 CRAN (R 3.3.1)                       
 parallel     3.3.1     2016-06-21 local                                
 pkgconfig    2.0.1     2017-03-21 CRAN (R 3.3.3)                       
 plyr         1.8.4     2016-06-08 CRAN (R 3.3.1)                       
 psych        1.6.9     2016-09-17 CRAN (R 3.3.1)                       
 purrr        0.2.2.2   2017-05-11 CRAN (R 3.3.3)                       
 R6           2.1.3     2016-08-19 CRAN (R 3.3.1)                       
 Rcpp         0.12.7    2016-09-05 CRAN (R 3.3.1)                       
 reshape2     1.4.1     2014-12-06 CRAN (R 3.3.1)                       
 rlang        0.1.1     2017-05-18 CRAN (R 3.3.3)                       
 scales       0.4.1     2016-11-09 CRAN (R 3.3.2)                       
 splines      3.3.1     2016-06-21 local                                
 stats      * 3.3.1     2016-06-21 local                                
 stringi      1.1.1     2016-05-27 CRAN (R 3.3.0)                       
 stringr      1.2.0     2017-02-18 CRAN (R 3.3.3)                       
 survival   * 2.41-3    2017-04-04 CRAN (R 3.3.3)                       
 survminer  * 0.4.0.999 2017-06-23 Github (kassambara/survminer@6fe5873)
 survMisc     0.5.4     2016-11-23 CRAN (R 3.3.3)                       
 tibble       1.3.3     2017-05-28 CRAN (R 3.3.3)                       
 tidyr        0.6.3     2017-05-15 CRAN (R 3.3.3)                       
 tools        3.3.1     2016-06-21 local                                
 utils      * 3.3.1     2016-06-21 local                                
 withr        1.0.2     2016-06-20 CRAN (R 3.3.1)                       
 xtable       1.8-2     2016-02-05 CRAN (R 3.3.1)                       
 zoo          1.7-13    2016-05-03 CRAN (R 3.3.1) 
@kassambara
Copy link
Owner

.get_data() works only when survfit() is used as follow:

fit <- survfit(Surv(futime, fustat) ~ 1, data = ovarian)
ggsurvplot(fit)

If you decide to use survfit() as follow (not recommended):

fit <- survfit(Surv(ovarian$futime, ovarian$fustat) ~ 1)

then, you should specify the argument data in ggsurvplot() as follow:

ggsurvplot(fit, data = ovarian)

@dnzmarcio
Copy link
Author

dnzmarcio commented Jun 24, 2017

Oh, I see. Thank you. Maybe a cleaner error message would be helpful:

.get_data <- function(fit, data = NULL, complain = TRUE) {
  if(is.null(data)){
    if (complain)
      warning ("The `data` argument is not provided. Data will be extracted from model fit.")
    data <- eval(fit$call$data)
    if (is.null(data))
      stop("The `data` argument should be provided either to ggsurvfit or survfit.")
  }
  data
}

@kassambara
Copy link
Owner

Ok, we'll clarify this. Thanks

kassambara added a commit that referenced this issue Oct 5, 2017
@kassambara
Copy link
Owner

fixed now, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants