Open maelle opened 2 years ago
@oggioniale : I had a look at chapter 12 of Hadley Wickham's book.
We should (must) have all R dependency packages listed in the DESCRIPTION file under Imports:. As it is now. This insures that whoever installs ReLTER will also have all the dependencies installed (>200). Installing all dependencies is done, of course, only once when a new user installs ReLTER.
On the other hand, the packages listed in NAMESPACE file are actually loaded (attached) every time you load ReLTER. This takes some time and memory. And probably is not necessary for many cases. When we specify a function, i.e. worrms::wm_records_names()
with the full package::function()
format then the wm_records_names()
function is found in the worrms
package even if that package is not loaded (attached). And we have been careful from the start to specify all function calls with that full format. So we can remove many (most) of the @import and @importFrom lines from many of the function definitions, and rerun devtools::document()
to rewrite the NAMESPACE file. Then all the rarely used packages will not be loaded from the start. This will make startup faster, avoid namespace collisions, and allow the package to use less memory.
@maelle : Any further comments on this?? Thanks
What's the specific question? In any case yes it is better to not import (in the NAMESPACE) a whole package when you use only a few functions of that package.
Here's what I see (not sure if this is the correct way to test...)
direct_deps <- remotes::local_package_deps()
length(direct_deps)
[1] 46
all_deps <- renv::dependencies()
Finding R package dependencies ... Done!
length(all_deps$Package)
[1] 401
So we are declaring@import
of 46 packages. And these are pulling along (recursively) another 350. And with all the importFrom()
lines in NAMESPACE we are actually attaching all these right from the start. Is this a problem?
Yes it is a problem, especially as there is a hard CRAN limit on direct Imports in DESCRIPTION (20 if I remember correctly).
For info @oggioniale, these might be useful when reducing the number of Imports.