[R-pkg-devel] import with except(ion)

Göran Broström gor@n@bro@trom @end|ng |rom umu@@e
Sat Oct 31 14:16:54 CET 2020



On 2020-10-31 13:49, Duncan Murdoch wrote:
> On 30/10/2020 2:45 p.m., Göran Broström wrote:
>> My CRAN package eha depends on the survival package, and that creates
>> problems with innocent users: It is about the 'frailty' function
>> (mainly). While (after 'library(eha)')
>>
>> f1 <- coxph(Surv(time, status) ~ age + frailty(inst), data = lung)
>>
>> produces what you would expect (a frailty survival analysis), the use of
>> the coxreg function from eha
>>
>> f2 <- coxreg(Surv(time, status) ~ age + frailty(inst), data = lung)
>>
>> produces (almost) nonsense. That's because the survival::frailty
>> function essentially returns its input and coxreg is happy with that,
>> treats it as an ordinary numeric (or factor) covariate, and nonsense is
>> produced, but some users think otherwise. (Maybe it would be better to
>> introduce frailty in a separate argument?)
>>
>> I want to prevent this to happen, but I do not understand how to do it
>> in the best way. I tried to move survival from Depends: to Imports: and
>> adding import(survival, except = c(frailty, cluster)) to NAMESPACE. This
>> had the side effect that a user must qualify the Surv function by
>> survival::Surv, not satisfactory (similarly for other popular functions
>> in survival).
>>
>> Another option I thought of was to define my own Surv function as
>> Surv <- survival::Surv in my package, but it doesn't feel right.
>> It seems to work, though.
>>
>> As you may understand from this, I am not very familiar with these
>> issues. I have used Depends: survival for a long time and been happy
>> with that.
>>
>> Any help on this is highly appreciated.
> 
> I don't know if you received any private replies, but I don't see any 
> public ones.

No replies so far.
> 
> It's not clear from your message what you would like to happen with 
> expressions like
> 
>   f2 <- coxreg(Surv(time, status) ~ age + frailty(inst), data = lung)
> 
> For example, would you like to generate an error, because you don't 
> support frailty in this context?  Could you clarify that?

Yes, this should generate an error. I think I have solved this problem 
by using importFrom(survival, ...), where I replace ... with all the 
functions I want from survival (not including frailty, cluster, ...)
and then export some of them. For now I have in NAMESPACE

importFrom(survival,Surv)
importFrom(survival,attrassign)
importFrom(survival,coxph)
importFrom(survival,strata)
importFrom(survival,untangle.specials)
...
export(Surv)
export(strata)

I also have to write documentation for Surv and strata.

Is this reasonable?

Göran

> 
> Duncan Murdoch



More information about the R-package-devel mailing list