[Rd] requireNamespace etiquette
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Feb 21 06:53:34 CET 2015
On 20/02/2015 21:15, RKoenker wrote:
> I'm trying to resolve a problem of Namespaces and probably have misunderstood
> something basic.
> In my quantreg package the function crq() has as its first argument a
> formula that typically contains
> something like this: Surv(y, ...) ~ foo, where Surv is a function from the
> survival package which
> quantreg suggests. When this syntax is encountered in ordinary usage Surv
> is resolved, I believe,
> because near the beginning of the crq code there is the locution:
> if(!requireNamespace("survival", quietly = TRUE))
> stop("crq requires survival package to be installed")
> However, when R CMD check tries to do one of the crq examples I see:
>> f <- crq(Surv(y,d,type = "left") ~ x, method = "Portnoy")
> Error in eval(expr, envir, enclos) : could not find function "Surv"
> Calls: crq ... eval -> model.frame -> model.frame.default -> eval -> eval
> Execution halted
> Can someone suggest a fix?
'Writing R Extensions' §184.108.40.206 does. Either use survival::Surv in that
call, or if your code expects only 'Surv', have
Surv <- survival::Surv
somewhere in the environment tree where your formula is evaluated.
Brian D. Ripley, ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK
More information about the R-devel