Some bugs identified in comments from JSS
Closed this issue · 1 comments
I'm recopying some of the comments we received related to bugs in casebase
:
> plot(fits[[1]])
Error in visreg(fit = list(coefficients = c(`(Intercept)` =
-7.76318709402459, :
could not find function "visreg"
And the comment goes:
The code contains
if (!requireNamespace("visreg", quietly = TRUE)) {
stop("visreg package needed for this function. please install
it first.")
}
tt <- do.call("visreg", utils::modifyList(list(fit = x,
trans = exp, plot = T, rug = FALSE, alpha = 1, partial = FALSE,
overlay = TRUE, print.cond = TRUE), hazard.params))
Well, Writing R Extensions would indicate that visreg::... needs to be used,
if one only checks availability of the package, but does not load it.
See https://cran.r-project.org/doc/manuals/R-exts.html#Suggested-packages
The first step would be to reproduce this error, perhaps by setting one of the Travis runs without the suggested packages. And if I read this comment correctly, the solution may simply be to replace do.call("visreg", ...)
with do.call("visreg::visreg", ...)
The next error is the following:
> fitSmoothHazard(DeadOfPrCa ~ ScrArm, data = ERSPC, ratio = 100, family =
"glmnet")
'Follow.Up.Time' will be used as the time variable
Error in glmnet(x, y, weights = weights, offset = offset, lambda = lambda, :
x should be a matrix with 2 or more columns
We've fixed some errors like this in the past, but this one is different: it's because the x
matrix only has one column: ScrArm
. This is definitely not the proper way of using glmnet
, but we should fail gracefully instead of relying on users to know what they're doing.
Here is a reproducible example of the first error. It occurs if you have visreg
installed but do not load the package. This behavior was well documented in our paper and vignettes. We specifically loaded the visreg package. In any case here is a reprex:
set.seed(12345)
library(casebase)
#> See example usage at http://sahirbhatnagar.com/casebase/
library(survival)
data(veteran)
veteran$prior <- factor(veteran$prior, levels = c(0, 10), labels = c("no","yes"))
veteran$celltype <- factor(veteran$celltype,
levels = c('large', 'squamous', 'smallcell', 'adeno'))
veteran$trt <- factor(veteran$trt, levels = c(1, 2), labels = c("standard", "test"))
model4 <- fitSmoothHazard(status ~ time + karno + diagtime + age + prior +
celltype + trt, data = veteran, ratio = 100)
#> 'time' will be used as the time variable
plot(model4)
#> Error in visreg(fit = structure(list(coefficients = c(`(Intercept)` = -2.71152013068635, : could not find function "visreg"
Created on 2021-02-02 by the reprex package (v0.3.0)
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.0.2 (2020-06-22)
#> os Pop!_OS 20.04 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en_US:en
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/Toronto
#> date 2021-02-02
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2)
#> backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.2)
#> callr 3.5.1 2020-10-13 [1] CRAN (R 4.0.2)
#> casebase * 0.9.0 2020-07-03 [1] CRAN (R 4.0.2)
#> cli 2.1.0 2020-10-12 [1] CRAN (R 4.0.2)
#> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.2)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.2)
#> data.table 1.13.0 2020-07-24 [1] CRAN (R 4.0.2)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.2)
#> devtools 2.3.2 2020-09-18 [1] CRAN (R 4.0.2)
#> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2)
#> dplyr 1.0.2 2020-08-18 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.2)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.0.2)
#> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.2)
#> ggplot2 3.3.2 2020-06-19 [1] CRAN (R 4.0.2)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.2)
#> highr 0.8 2019-03-20 [1] CRAN (R 4.0.2)
#> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2)
#> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.2)
#> lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.2)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.2)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2)
#> Matrix 1.2-18 2019-11-27 [4] CRAN (R 4.0.0)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.2)
#> mgcv 1.8-33 2020-08-27 [4] CRAN (R 4.0.2)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.2)
#> nlme 3.1-149 2020-08-23 [4] CRAN (R 4.0.2)
#> pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
#> pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
#> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.2)
#> processx 3.4.4 2020-09-03 [1] CRAN (R 4.0.2)
#> ps 1.4.0 2020-10-07 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.2)
#> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2)
#> remotes 2.2.0 2020-07-21 [1] CRAN (R 4.0.2)
#> rlang 0.4.9 2020-11-26 [1] CRAN (R 4.0.2)
#> rmarkdown 2.5.3 2020-10-31 [1] Github (rstudio/rmarkdown@62d9b6b)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.2)
#> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> survival * 3.2-3 2020-06-13 [1] CRAN (R 4.0.2)
#> testthat 3.0.0 2020-10-31 [1] CRAN (R 4.0.2)
#> tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.2)
#> usethis 1.6.3 2020-09-17 [1] CRAN (R 4.0.2)
#> vctrs 0.3.4 2020-08-29 [1] CRAN (R 4.0.2)
#> VGAM 1.1-3 2020-04-28 [1] CRAN (R 4.0.2)
#> visreg 2.7.0 2020-06-04 [1] CRAN (R 4.0.2)
#> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2)
#> xfun 0.19 2020-10-30 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.2)
#>
#> [1] /home/sahir/R/x86_64-pc-linux-gnu-library/4.0
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library