import the same PACKAGE in several R files
Asked Answered
N

1

5

When writing an R package, I need to import another R package B. I use the roxygen2 for the documentation.

My question is, if I have several R functions using the package B, should I write

#' @import B

for each function, or it is suffericent to only write one time.

Nutriment answered 27/7, 2018 at 14:48 Comment(3)
Have you tried just writing it once? Was there a problem? Seems like something that's pretty easy to test. If you have problems, try to give a specific error message or a simple reproducible example so we can see what's really going on in order to give a more precise answer.Triangle
If you are trying to import a function for use in your package then you only need to use @import [function to import] once. Then it will be available throughout your package as long it is also in your DESCRIPTION file as an import. Often I think it is just easier to reference the package directly using ::Sizeable
It is sufficient to import once, but you can import several times without issue (that's useful if you want to copy-paste in another package for example).Thumbnail
U
7

As mentioned in the comments, you only need to import it once, but importing it many times doesn't cause any problems.

If you don't want to import it in every function, but are worried about tying it to a single function (what if you only import it on function foo, but later you decided to replace foo with bar and lose the import) you can add all your shared import statements to NULL at the top of the document:

#' @import ggplot2
#' @import B
#' @import dplyr
NULL

roxygen2 will happily create the proper import statements in NAMESPACE, but you'll only have the imports listed once in a convenient place without tying them to any particular package

Undercool answered 1/8, 2018 at 19:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.