2

I have read through numerous posts on this topic and have spend far too much time to try to get it right. So I finally decided to write yet another question on the topic.

What I want is to use the NAMESPACE file with import/importFrom correct. The problem is that I get a warning upon the RCMD check (which is not appreciated on CRAN):

Warning: replacing previous import by 'gtable::gtable' when loading 'strvalidator'

It is similar to this and this question but none of them make me any wiser.

My package (full code here) use the gtable function from both the gtable and the gWidgets package so the solutions to only import functions that you use or change the order of import does not solve the problem. I always use the double colon for the gtable functions (i.e. gtable::gtable and gWidgets::gtable) as pointed out in this and this post.

I use importFrom for all functions (as pointed out here) except for the packages where I use numerous functions (here I use import instead. I have tested with importFrom but it gives the same warning).

Any help is highly appreciated!

EDIT: So I will add what I ended up doing as requested by @catastrophic-failure. I think I can't add a proper answer because this question is a duplicate. Instead I add the solution as an edit:

I ended up removing all the importFrom from the NAMESPACE file. The four main packages that I use without :: has import in the NAMESPACE. Other package functions are used with :: and their packages are listed (together with the four main packages) as Imports in the DESCRIPTION file. This approach works (i.e. does not give me any errors), but does not make use of the importFrom.

Community
  • 1
  • 1
Oskar Hansson
  • 331
  • 4
  • 15
  • You seem to be making trouble for yourself. Why not just `require(gtable)` and `require(gwidgets)` and call the specific functions via colons? Or alternatively, copy the code , with attribution, and include a `my_gtable` function in your package. – Carl Witthoft Oct 13 '14 at 11:38
  • Thanks, that will probably get rid of the warning. But it is the preferred way? I got the impression that `import/importFrom` was encourage over `require` (see [this](https://stat.ethz.ch/pipermail/r-help/2013-August/358754.html)). I am still confused about many things on how to make R packages, so there are plenty of room for improvements... – Oskar Hansson Oct 13 '14 at 13:04
  • Good point; I guess my personal approach would be to consider your situation one in which you can justify using `require` . – Carl Witthoft Oct 13 '14 at 13:11
  • 1
    I ended up removing all the `importFrom` from the NAMESPACE file. The four main packages that I use without `::` has `import` in the NAMESPACE. Other package functions are used with `::` and their packages are listed (together with the four main packages) as `Imports` in the DESCRIPTION file. This approach works (i.e. does not give me any errors), but does not make use of the `importFrom`. – Oskar Hansson Oct 20 '14 at 13:05
  • @OskarHansson Please add your solution as an answer so it's readily visible. – catastrophic-failure Jul 13 '16 at 16:12
  • I find using `::` produces more readable code since you always know where the function comes from. That is also what Hadley recommends in http://r-pkgs.had.co.nz/namespace.html (section "Imports"). The only things I usually import are stuff like `%>%` and the whole assertthat package. – Stefan F Jul 22 '17 at 07:26

0 Answers0