kassambara / survminer

Survival Analysis and Visualization
https://rpkgs.datanovia.com/survminer/
491 stars 160 forks source link

surv_pvalue error with functionally derived survfit objects #417

Open kieranzu opened 5 years ago

kieranzu commented 5 years ago

Expected behavior

If I hard code Km models in the usual way then i can run surv_pvalue without any problem. As I am building multiple models for multiple cancers I am writing custom functions that build the KM models for multiple cancer sites simultaneously. I would expect the models built in this fashion to work in the same way as those that are hard coded

Actual behavior

When I attempt to run surv_pvalue on the functionally generated models i get the following: Error in paste(x) : object 'x' not found This seems to be due to the call element of the survfit object having the raw text from the function used to generate it rather than the string after pasting.

Steps to reproduce the problem

Sites<- c("colon")

colon_Surv <- Surv(time = colon$time, event = colon$etype)

Test_Fits<- function(x){ assign(paste("Test", x, "Fit", sep =""),
                               survfit(get(paste(x,"Surv", sep="_")) ~ nodes, 
                                       data = get(paste(x))), envir = .GlobalEnv)}

sapply(Sites, Test_Fits)

surv_pvalue(TestcolonFit)

session_info()

- Session info --------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.3 (2019-03-11)
 os       Windows 7 x64 SP 1          
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United Kingdom.1252 
 ctype    English_United Kingdom.1252 
 tz       Europe/London               
 date     2019-08-07                  

- Packages ------------------------------------------------------------------------------------------
 ! package      * version    date       lib source        
   assertthat     0.2.1      2019-03-21 [1] CRAN (R 3.5.3)
   backports      1.1.4      2019-04-10 [1] CRAN (R 3.5.3)
   BiocManager    1.30.4     2018-11-13 [1] CRAN (R 3.5.3)
   bit            1.1-14     2018-05-29 [1] CRAN (R 3.5.2)
   bit64          0.9-7      2017-05-08 [1] CRAN (R 3.5.2)
   boot         * 1.3-20     2017-08-06 [2] CRAN (R 3.5.3)
   broom          0.5.2      2019-04-07 [1] CRAN (R 3.5.3)
   callr          3.2.0      2019-03-15 [1] CRAN (R 3.5.3)
   cli            1.1.0      2019-03-19 [1] CRAN (R 3.5.3)
   cmprsk         2.2-7      2014-06-17 [1] CRAN (R 3.5.3)
   codetools      0.2-16     2018-12-24 [2] CRAN (R 3.5.3)
   colorspace     1.4-1      2019-03-18 [1] CRAN (R 3.5.3)
   crayon         1.3.4      2017-09-16 [1] CRAN (R 3.5.3)
   data.table   * 1.12.2     2019-04-07 [1] CRAN (R 3.5.3)
   desc           1.2.0      2018-05-01 [1] CRAN (R 3.5.3)
   devtools       2.0.2      2019-04-08 [1] CRAN (R 3.5.3)
   digest         0.6.18     2018-10-10 [1] CRAN (R 3.5.3)
   dplyr        * 0.8.0.1    2019-02-15 [1] CRAN (R 3.5.3)
   foreach        1.4.4      2017-12-12 [1] CRAN (R 3.5.3)
   foreign        0.8-71     2018-07-20 [2] CRAN (R 3.5.3)
   fs             1.3.1      2019-05-06 [1] CRAN (R 3.5.3)
   generics       0.0.2      2018-11-29 [1] CRAN (R 3.5.3)
   ggfortify    * 0.4.6      2019-03-20 [1] CRAN (R 3.5.3)
   ggplot2      * 3.1.1      2019-04-07 [1] CRAN (R 3.5.3)
   ggpubr       * 0.2        2018-11-15 [1] CRAN (R 3.5.3)
   glue           1.3.1      2019-03-12 [1] CRAN (R 3.5.3)
   gridExtra    * 2.3        2017-09-09 [1] CRAN (R 3.5.3)
   gtable         0.3.0      2019-03-25 [1] CRAN (R 3.5.3)
   iterators      1.0.10     2018-07-13 [1] CRAN (R 3.5.3)
   km.ci          0.5-2      2009-08-30 [1] CRAN (R 3.5.3)
   KMsurv         0.1-5      2012-12-03 [1] CRAN (R 3.5.2)
   knitr          1.22       2019-03-08 [1] CRAN (R 3.5.3)
   lattice        0.20-38    2018-11-04 [2] CRAN (R 3.5.3)
   lava           1.6.5      2019-02-12 [1] CRAN (R 3.5.3)
   lazyeval       0.2.2      2019-03-15 [1] CRAN (R 3.5.3)
   lubridate    * 1.7.4      2018-04-11 [1] CRAN (R 3.5.3)
   magrittr     * 1.5        2014-11-22 [1] CRAN (R 3.5.3)
   MASS         * 7.3-51.1   2018-11-01 [2] CRAN (R 3.5.3)
   Matrix         1.2-15     2018-11-01 [2] CRAN (R 3.5.3)
   memoise        1.1.0      2017-04-21 [1] CRAN (R 3.5.3)
   mnormt         1.5-5      2016-10-15 [1] CRAN (R 3.5.2)
   munsell        0.5.0      2018-06-12 [1] CRAN (R 3.5.3)
   nlme           3.1-137    2018-04-07 [2] CRAN (R 3.5.3)
   nortest      * 1.0-4      2015-07-30 [1] CRAN (R 3.5.2)
   numDeriv       2016.8-1.1 2019-06-06 [1] CRAN (R 3.5.3)
   pacman       * 0.5.1      2019-03-11 [1] CRAN (R 3.5.3)
   pec            2018.07.26 2018-07-26 [1] CRAN (R 3.5.3)
   pillar         1.4.0      2019-05-11 [1] CRAN (R 3.5.3)
   pkgbuild       1.0.3      2019-03-20 [1] CRAN (R 3.5.3)
   pkgconfig      2.0.2      2018-08-16 [1] CRAN (R 3.5.3)
   pkgload        1.0.2      2018-10-29 [1] CRAN (R 3.5.3)
   plyr         * 1.8.4      2016-06-08 [1] CRAN (R 3.5.3)
   prettyunits    1.0.2      2015-07-13 [1] CRAN (R 3.5.3)
   processx       3.3.1      2019-05-08 [1] CRAN (R 3.5.3)
   prodlim        2018.04.18 2018-04-18 [1] CRAN (R 3.5.3)
   ps             1.3.0      2018-12-21 [1] CRAN (R 3.5.3)
   pscl         * 1.5.2      2017-10-10 [1] CRAN (R 3.5.3)
   psych        * 1.8.12     2019-01-12 [1] CRAN (R 3.5.3)
   purrr        * 0.3.2      2019-03-15 [1] CRAN (R 3.5.3)
   R6             2.4.0      2019-02-14 [1] CRAN (R 3.5.3)
   RColorBrewer * 1.1-2      2014-12-07 [1] CRAN (R 3.5.2)
   Rcpp           1.0.1      2019-03-17 [1] CRAN (R 3.5.3)
   remotes        2.0.4      2019-04-10 [1] CRAN (R 3.5.3)
 D rJava          0.9-11     2019-03-29 [1] CRAN (R 3.5.3)
   rlang          0.3.4      2019-04-07 [1] CRAN (R 3.5.3)
   RODBC        * 1.3-15     2017-04-13 [1] CRAN (R 3.5.2)
   rprojroot      1.3-2      2018-01-03 [1] CRAN (R 3.5.3)
   rstudioapi     0.10       2019-03-19 [1] CRAN (R 3.5.3)
   scales         1.0.0      2018-08-09 [1] CRAN (R 3.5.3)
   sessioninfo    1.1.1      2018-11-05 [1] CRAN (R 3.5.3)
   sm           * 2.2-5.6    2018-09-27 [1] CRAN (R 3.5.3)
   stringi        1.4.3      2019-03-12 [1] CRAN (R 3.5.3)
   stringr      * 1.4.0      2019-02-10 [1] CRAN (R 3.5.3)
   survival     * 2.43-3     2018-11-26 [2] CRAN (R 3.5.3)
   survminer    * 0.4.3      2018-08-04 [1] CRAN (R 3.5.3)
   survMisc       0.5.5      2018-07-05 [1] CRAN (R 3.5.3)
   tibble         2.1.1      2019-03-16 [1] CRAN (R 3.5.3)
   tidyr        * 0.8.3      2019-03-01 [1] CRAN (R 3.5.3)
   tidyselect   * 0.2.5      2018-10-11 [1] CRAN (R 3.5.3)
   timereg        1.9.3      2019-01-14 [1] CRAN (R 3.5.3)
   usethis        1.5.0      2019-04-07 [1] CRAN (R 3.5.3)
   withr          2.1.2      2018-03-15 [1] CRAN (R 3.5.3)
   xfun           0.7        2019-05-14 [1] CRAN (R 3.5.3)
   xlsx         * 0.6.1      2018-06-11 [1] CRAN (R 3.5.3)
   xlsxjars       0.6.1      2014-08-22 [1] CRAN (R 3.5.3)
   xtable         1.8-4      2019-04-21 [1] CRAN (R 3.5.3)
   zoo            1.8-5      2019-03-21 [1] CRAN (R 3.5.3)
chrisamiller commented 4 months ago

I'm having this same issue, many years later. Was a solution ever found?

chrisamiller commented 4 months ago

Found a workaround that requires a loop and creating a new dataframe with identically named columns for every iteration (instead of substituting columns into the formula). It's not ideal, but gets the job done.