I'm writing a package that imports (and uses) both SparkR::sql
and dbplyr::sql
. The other relevant questions involve unintentional collisions brought on my haphazard import
ing.
In my NAMESPACE
I have:
importFrom(dbplyr, sql)
importFrom(SparkR, sql)
Both of these functions are used in the script and, being aware of the conflict, I'm sure to always prefix the package name:
dbplyr::sql(...)
SparkR::sql(...)
Nevertheless, I get an import replacement warning when building/checking the package:
Warning: replacing previous import ‘dbplyr::sql’ by ‘SparkR::sql’ when loading ‘my_pkg’
What I see in Writing R Extensions seems to be the following:
If a package only needs a few objects from another package it can use a fully qualified variable reference [
foo::f
] in the code instead of a formal import... This is slightly less efficient than a formal import and also loses the advantage of recording all dependencies in theNAMESPACE
file (but they still need to be recorded in theDESCRIPTION
file). Evaluatingfoo::f
will cause packagefoo
to be loaded, but not attached, if it was not loaded already—this can be an advantage in delaying the loading of a rarely used package.
Am I right that the takeaway of this / best practice is to:
- Pick which function is used most often and add that to
importFrom
- Remove the "less-frequent" function from
importFrom
but keep that package inDESCRIPTION
- Just use
::
(perhaps preceded byrequire()
) for the "less-frequent" function