An R package providing a selective import mechanism for functions from packages and modules, avoiding namespace pollution.
import is an R package that provides a selective import mechanism for functions from external packages and custom R module scripts. It solves the problem of namespace pollution and masking conflicts that occur when loading entire packages with `library()`, allowing developers to import only the specific functions they need.
R developers and data scientists who work with multiple packages and want to avoid namespace conflicts, improve code clarity, and adopt modular programming practices in their scripts and projects.
Developers choose import over base R's `library()` because it offers precise control over function imports, prevents naming conflicts, supports custom modules, and integrates seamlessly into existing workflows without requiring major changes to code structure.
An Import Mechanism For R
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows importing only specific functions from packages, preventing masking conflicts and reducing memory overhead, as demonstrated by importing just impute() and nomiss() from Hmisc instead of all 400+ functions.
Enables importing functions from external R script files (modules), facilitating code modularity and reuse, shown with examples like sequence_module.R for mathematical functions.
Easy aliasing of functions to avoid naming clashes, such as renaming dplyr's filter to keep_when, improving code clarity without altering logic.
Offers fine-grained control with .all, .except, .into, and .character_only for complex scenarios, like grouping imports into custom search path entities or handling variable names.
Base R's library() now includes include.only and exclude arguments for selective imports, making import less essential for basic use cases, as noted in the 'See also' section.
Requires .character_only=TRUE for importing from variable names (e.g., module_name), adding an extra step and complexity compared to symbolic evaluation, which can be error-prone.
Default behavior has shifted, such as the .library parameter changing from using only the first library path to all paths in version 1.3.0, which could disrupt existing workflows without clear migration paths.