Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load only specific functions from a package

Tags:

r

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?

like image 502
Brandon Bertelsen Avatar asked Oct 30 '12 20:10

Brandon Bertelsen


People also ask

Which function is used to load a package?

Which function is used for loading packages? Explanation: library() function is used to load a package.

What function and packages in R?

R packages are a collection of R functions, complied code and sample data. They are stored under a directory called "library" in the R environment. By default, R installs a set of packages during installation. More packages are added later, when they are needed for some specific purpose.


1 Answers

Sure. Just use an importFrom directive in your NAMESPACE file (as described here in R-exts).

importFrom(gdata, trim)

OP EDIT: As of R 3.2.0 there's now a base function: trimws()

like image 107
Josh O'Brien Avatar answered Nov 12 '22 00:11

Josh O'Brien