1

I want to use the R package survival in my own R package.

My problem is that the function predict.coxph is not exported by survival, which is why I cannot use survival::predict.coxph listing survival under Imports: in the DESCRIPTION file.

Now I tried to list survival under Depends: and just use predict(fittedmodel) (and coxph and Surv without survival::). But I get the following NOTEs using R CMD check --as-cran:

  1. "* checking dependencies in R code ... NOTE Package in Depends field not imported from: 'survival' These packages need to be imported from (in the NAMESPACE file) for when this namespace is loaded but not attached."
  2. "no visible global function definition for 'Surv'" etc.
  3. "Undefined global functions or variables: Surv coxph survfit"

Regarding 1): I have import(survival) in the NAMESPACE file.

What would be the problem here?

user3298179
  • 163
  • 9

1 Answers1

0

According to the Writing R Packages Manual

Using foo:::f instead of foo::f allows access to unexported objects. This is generally not recommended, as the semantics of unexported objects may be changed by the package author in routine maintenance.

So there you have it. To access unexported functions, you just have to call them using ::: instead of ::, but be aware of the fact that those functions have no documentation available, so their use may change when new versions of the package in question is released.

About your dependencies issue, simply add survival to the Imports section of the DESCRIPTION.

eduardokapp
  • 1,612
  • 1
  • 6
  • 28
  • Thanks! I have used `:::` now, but unfortunately I get: "* checking dependencies in R code ... WARNING Unexported object imported by a ':::' call: 'survival:::predict.coxph' See the note in ?::: about the use of this operator. Including base/recommended package(s): 'survival'". Would there be any other possibility? There should probably be a way to use `predict.coxph`, since `survival` is a very commonly used R package. – user3298179 Mar 26 '21 at 20:41
  • `predict.coxph` does have a help page. So it is an exception to the common practice of not including documentation for non-exported functions. I'm not able to explain why that function is not exported. – IRTFM Apr 03 '21 at 21:21