Devtools::load_all() doesn't load imports in the NAMESPACE


#1

I am working on an internal package. Because I use dplyr a lot it and it is for my own use only, it seems sensible to import it. I added the roxygen tag #' import dplyr to my code and after running devtools::document() the tag import(dplyr) indeed was added to the NAMESPACE file.

I expected that after running devtools::load_all() the functions from dplyr would now be available. However, this is not the case. Functions calling dplyr functions break with “could not find …” error message. What am I overlooking or misunderstanding? Thanks!


#2

You must use dplyr::function to call a function. If you really want to load dplyr in your project, you can do it with library. However, the latter is not recommended in most cases. If this doesn’t work, then dplyr might not be installed.


#3

The devel version of devtools does this, so you can use that if you are really looking for this feature.

devtools::install_github("devtools")

Be sure to run devtools::document() after adding the @import directive so the NAMESPACE is properly created.


#4

Thanks for your reply, but I think you are mixing up the Imports field in the DESCRIPTION file with adding import(pkg) to the NAMESPACE. I am referring to the latter, this should load all the functions from the package. In case of the former you should indeed refer to functions with pkg::fun.


#5

Indeed. I guess my response was more of a quick shot missing the point.
Thanks for clarifying. :slight_smile:


#6

Hi @Edwin, I noticed that your example roxygen #' import dplyr was missing the @ in @import, was that part of the problem?