Import specific funcitons instead of entire pakcages
maurolepore opened this issue · 4 comments
Unless you are using a lot of funcitons from a package, it's best to import specific functions instead of all of them.
GOOD
#' @importFrom BIOMASS function1 function2 ...
BAD
#' @import BIOMASS
@ervanSTRI, RE:
#' @imports BIOMASS # how do I force the usage of this package (mandatory for this funtion to work)
@imports
is not a valid tag. It causes devtools::document()
to fail:
The valid tag is @import
(without the trailing s). Your package right now imports all functions from data.table and all functions from BIOMASS. For clarity, I moved the calls to @import
to R/imports.R. This is common practice.
But, it is best to not use @import
but use @importFrom
instead. See my comment above. Best of all is to avoid these tags completele and instead use the package::funciton() syntax. See http://r-pkgs.had.co.nz/namespace.html.
Also, just to clarify, your examples don't need to run devtools::use_package()
. That function is not for user but for developers. We already run it. The effect is to write the name of a package in DESCRIPTION, under Imports:
.
The packages listed under Imports:
, will be installed when the user installs __AGBfluxes. Hopefully the chapter on NAMESPACE (link above) will clarify this.
The commit 97b4211 shows how to refer to functions from other packages.
This example uses the package stats. First, I run use_package("stats")
to add stats to DESCRIPTION, under Imports
. Then I refer to functions as stats::funciton()
, for example, stats::approx()
. You can avoid using the syntax package::function()
if you add the tag @import stats
, but that is bad practice because it will contaminate the namespace of your package with all the functions from stats, when you indeed need only a few.
We are on top of this now.