import_inops | R Documentation |
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)
import_inops(expose = NULL, unexpose = NULL, lib.loc = .libPaths(), ...)
expose , unexpose |
either one of the following:
|
lib.loc |
character vector specifying library search path
(the location of R library trees to search through). |
... |
additional arguments,
only relevant if the |
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.
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
.
tinycodet_import, import_inops.control()
, report_inops()
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.)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.