It seems like {survival} needs to be attached via library(rms) or library(survival) for npsurv() to work. Issue found in a package where I don't attach packages but use package:: namespacing.
Steps to reproduce; from a fresh session.
> set.seed(1)
> data <- data.frame(var = sample(c("a", "b"), 10, replace = TRUE), surv = survival::Surv(1:10, runif(10) < 0.5))
> data
var surv
1 a 1
2 b 2
3 a 3+
4 a 4
5 b 5+
6 a 6
7 a 7+
8 a 8+
9 b 9
10 b 10+
> rms::npsurv(surv ~ var, data = data)
Error in survfit(formula = surv ~ var, data = data) :
could not find function "survfit"
> library(survival)
> rms::npsurv(surv ~ var, data = data)
Call: rms::npsurv(formula = surv ~ var, data = data)
n events median 0.95LCL 0.95UCL
var=a 6 3 6 4 NA
var=b 4 2 9 2 NA
Workaround: I #' @import survival and devtools::document() in my package to have {survival} attached.
It seems like
{survival}
needs to be attached vialibrary(rms)
orlibrary(survival)
fornpsurv()
to work. Issue found in a package where I don't attach packages but usepackage::
namespacing.Steps to reproduce; from a fresh session.
Workaround: I
#' @import survival
anddevtools::document()
in my package to have{survival}
attached.