fkoh111 / fkoh111utils

Assorted utils :wrench: :construction_worker:
GNU Lesser General Public License v3.0
0 stars 0 forks source link

task/import_specific_dependencies #67

Closed fkoh111 closed 4 years ago

fkoh111 commented 4 years ago

Instead of importing an entire package, import specifics:

http://r-pkgs.had.co.nz/namespace.html

fkoh111 commented 4 years ago

If you are using just a few functions from another package, my recommendation is to note the package name in the Imports: field of the DESCRIPTION file and call the function(s) explicitly using ::, e.g., pkg::fun(). Operators can also be imported in a similar manner, e.g., @importFrom magrittr %>%.

If you are using functions repeatedly, you can avoid :: by importing the function with @importFrom pkg fun. This also has a small performance benefit, because :: adds approximately 5 µs to function evaluation time.

Alternatively, if you are repeatedly using many functions from another package, you can import all of them using @import package. This is the least recommended solution because it makes your code harder to read (you can’t tell where a function is coming from), and if you @import many packages, it increases the chance of conflicting function names.