This question has been asked before (Include library calls in functions?) but I wonder if there are any new takes on it.
Putting library()
calls inside functions is something I am often tempted to do. It means the function is slightly more portable; it will run without errors if a colleague copies it into their own project, for example.
The main downside seems to be "global effects", which I guess refers to namespace clashes. Are there other worries?
The alternatives seem to be:
- Load packages at the top of the script containing the functions. But how does a colleague who wants to copy the function know which package is required for which function? (I guess the function documentation should cover this?).
- Build a package. But the ROI on this may be low for small-scale projects.