import_inops: (Un)Expose Infix Operators From Package Namespace in the...

View source: R/import_inops.R

import_inopsR Documentation

(Un)Expose Infix Operators From Package Namespace in the Current Environment

Description

import_inops(expose = ...) exposes infix operators specified in a package or an alias object to the current environment.

import_inops(unexpose = ...) "unexposes" (i.e. removes) the infix operators specified in a package or an alias object from the current environment.
Note that in this case only infix operators exposed by the 'tinycodet' import system will be removed from the current environment; "regular" (i.e. user-defined) infix operators will not be touched.

To attach all infix operators from a package to the global namespace, one can use the pkg_lsf function like so:

y <- pkg_lsf("packagename", type = "inops")
library(packagename, include.only = y)

Usage

import_inops(expose = NULL, unexpose = NULL, lib.loc = .libPaths(), ...)

Arguments

expose, unexpose

either one of the following:

  • an alias object as produced by the import_as function.

  • a string giving the package name. Core R (i.e. "base", "stats", etc.) is not allowed.

lib.loc

character vector specifying library search path (the location of R library trees to search through).
Only used when supplying a string to expose / unexpose, and ignored when supplying an alias object to expose / unexpose (the library is path already stored inside the alias object).
The lib.loc argument would usually be .libPaths().
See also loadNamespace.

...

additional arguments, only relevant if the expose argument is used.
See import_inops.control.

Details

Why Exposing Infix Operators Is Useful
To use a function from an R-package, while avoiding the disadvantages of attaching a package (see tinycodet_import), one would traditionally use the :: operator like so:

packagename::function_name()

This is, however, cumbersome with infix operators, as it forces one to code like this:

packagename::`%op%`(x,y)

Exposing infix operators to the current environment, using the import_inops() function, allows one to use infix operators without using cumbersome code, and without having to attach the infix operators globally.


Other Details
The import_inops() function does not support overloading base/core R operators.

When using import_inops() to remove infix operators from the current environment, it will use the attributes of those operators to determine if the infix operator came from the 'tinycodet' import system or not. Only infix operators exposed by the 'tinycodet' import system will be removed.

Value

If using argument expose:
The infix operators specified in the given package or alias will be placed in the current environment.

If using argument unexpose:
The infix operators specified in the given package or alias, exposed by import_inops(), will be removed from the current environment.
If such infix operators could not be found, this function simply returns NULL.

See Also

tinycodet_import, import_inops.control(), report_inops()

Examples


import_inops(expose = "stringi") # expose infix operators from package
import_inops(unexpose = "stringi") # remove the exposed infix operators from environment

import_as(~ stri., "stringi")
import_inops(expose = stri.) # expose infix operators from alias
import_inops(unexpose = stri.) # unexposed infix operators from current environment


# additional arguments (only used when exposing, not unexposing):
import_inops(expose = "stringi", exclude = "%s==%")
import_inops(unexpose = "stringi")
import_inops(expose = "stringi", overwrite = FALSE)
import_inops(unexpose = "stringi")

import_as(~ stri., "stringi")
import_inops(expose = stri., include.only = "%s==%")
import_inops(unexpose = stri.)
import_inops(expose = stri., overwrite = FALSE)
import_inops(unexpose = stri.)





tinycodet documentation built on Sept. 12, 2024, 7:03 a.m.