I often use utility type functions from other packages that are un-exported:
pkg:::fun()
. I am wondering if I can use such a function within new functionality/scope in my own R package. What is the correct approach here? Is including the package in my description file enough?
Using un-exported function from another R package?
Summarising comments from @baptise, and etc...:
:::
not allowed on CRAN, so options:- ask author to export it so you can use it in your package via standard imports or suggests.
- copy / lift a version of it and clearly cite within your package.
Another trick is using getFromNamespace()
:
fun <- utils::getFromNamespace("fun", "pkg")
The only advantage over :::
is that you don't get any NOTEs and it's allowed on CRAN. Of course, this is not good practice as a hidden change in pkg
can break your package.
Note: With roxygen2 you have to add the utils
package to the Imports
field of your DESCRIPTION
file to fulfill CRAN's requirements. Alternatively, you can put it in your NAMESPACE
manually.
I just tested this and it worked perfectly. Eliminates need to copy/paste function from other package. –
Calyptrogen
Is this practice still permitted on
CRAN
in 2022? –
Radack Summarising comments from @baptise, and etc...:
:::
not allowed on CRAN, so options:- ask author to export it so you can use it in your package via standard imports or suggests.
- copy / lift a version of it and clearly cite within your package.
© 2022 - 2024 — McMap. All rights reserved.
borrowedfun <- pkg:::fun()
and put the package in Suggests. Making sure the original author is okay with it is a good idea. Or just ask them if you can just use the exact function in your own package. – Lucky:::
is not allowed in CRAN packages. You should ask the original package author to export it, or, alternatively, permission to include a copy in your own package. – Bondman