I have a package that uses the trim() function in the gdata package. I literally use nothing else from the package and (as some of you may have seen) it overwrites some functionality of base R that I need.
Is there a way to load only one function rather than the whole package?
Sure. Just use an
importFrom
directive in your NAMESPACE file (as described here in R-exts).OP EDIT: As of R 3.2.0 there's now a base function:
trimws()
Now I get it: from another post: It means the package (In this case R) can access the package functions/objects, but the user can not without explicitly loading the tools package where as stats, graphics, etc. are loaded and ready to go for the user.
So -- the formally specified import (in which you specify 'Imports: survival' in the description file and also 'importFrom(survival, Surv)' in the NAMESPACE file does indeed work, but then, without also adding 'Surv' to the list of 'export' -ed objects, the function 'Surv' is only available to the code inside the package but not to the user (and hence not available to examples in vignettes either).