From ripley at stats.ox.ac.uk  Sat Feb 21 06:53:34 2015
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sat, 21 Feb 2015 05:53:34 +0000
Subject: [Rd] requireNamespace etiquette
In-Reply-To: <1424466957867-4703620.post@n4.nabble.com>
References: <1424466957867-4703620.post@n4.nabble.com>
Message-ID: <54E81D5E.1060208@stats.ox.ac.uk>

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' ?1.1.3.1 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.

>
> Roger

-- 
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



[Rd] requireNamespace etiquette
Prof Brian Ripley