Title: | An Import Mechanism for R |
---|---|
Description: | Alternative mechanism for importing objects from packages and R modules. The syntax allows for importing multiple objects with a single command in an expressive way. The import package bridges some of the gap between using library (or require) and direct (single-object) imports. Furthermore the imported objects are not placed in the current environment. |
Authors: | Stefan Milton Bache [aut], Magnus Thor Torfason [aut, cre] |
Maintainer: | Magnus Thor Torfason <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.3.2 |
Built: | 2024-11-12 04:40:36 UTC |
Source: | https://github.com/rticulate/import |
The import::from
and import::into
functions provide an alternative way to
import objects (e.g. functions) from packages. It is sometimes preferred over
using library
(or require
) which will import all objects exported by the
package. The benefit over obj <- pkg::obj
is that the imported objects will
(by default) be placed in a separate entry in the search path (which can be
specified), rather in the global/current environment. Also, it is a more
succinct way of importing several objects. Note that the two functions are
symmetric, and usage is a matter of preference and whether specifying the
.into
argument is desired. The function import::here
imports into the
current environment.
from( .from, ..., .into = "imports", .library = .libPaths(), .directory = ".", .all = (length(.except) > 0), .except = character(), .chdir = TRUE, .character_only = FALSE, .S3 = FALSE ) here( .from, ..., .library = .libPaths()[1L], .directory = ".", .all = (length(.except) > 0), .except = character(), .chdir = TRUE, .character_only = FALSE, .S3 = FALSE ) into( .into, ..., .from, .library = .libPaths()[1L], .directory = ".", .all = (length(.except) > 0), .except = character(), .chdir = TRUE, .character_only = FALSE, .S3 = FALSE )
from( .from, ..., .into = "imports", .library = .libPaths(), .directory = ".", .all = (length(.except) > 0), .except = character(), .chdir = TRUE, .character_only = FALSE, .S3 = FALSE ) here( .from, ..., .library = .libPaths()[1L], .directory = ".", .all = (length(.except) > 0), .except = character(), .chdir = TRUE, .character_only = FALSE, .S3 = FALSE ) into( .into, ..., .from, .library = .libPaths()[1L], .directory = ".", .all = (length(.except) > 0), .except = character(), .chdir = TRUE, .character_only = FALSE, .S3 = FALSE )
The function arguments can be quoted or unquoted as with e.g. library
. In
any case, the character representation is used when unquoted arguments are
provided (and not the value of objects with matching names). The period in
the argument names .into
and .from
are there to avoid name clash with
package objects. However, while importing of hidden objects (those with names
prefixed by a period) is supported, care should be taken not to conflict with
the argument names. The double-colon syntax import::from
allows for imports
of exported objects (and lazy data) only. To import objects that are not
exported, use triple-colon syntax, e.g. import:::from
. The two ways of
calling the import
functions analogue the ::
and :::
operators
themselves.
Note that the import
functions usually have the (intended) side-effect of
altering the search path, as they (by default) import objects into the
"imports" search path entry rather than the global environment.
The import
package is not meant to be loaded with library
(and will
output a message about this if attached), but rather it is named to make the
function calls expressive without the need to loading before use, i.e. it is
designed to be used explicitly with the ::
syntax, e.g. import::from(pkg, x, y)
.
a reference to the environment containing the imported objects.
import
can either be used to import objects either from R packages or from
R
source files. If the .from
parameter ends with '.R' or '.r', import
will look for a source file to import from. A source file in this context is
referred to as a module
in the documentation.
With import
you can specify package version requirements. To do this add a
requirement in parentheses to the package name (which then needs to be
quoted), e.g import::from("parallel (>= 3.2.0)", ...)
. You can use the
operators <
, >
, <=
, >=
, ==
, !=
. Whitespace in the specification
is irrelevant.
Helpful links:
import::from(parallel, makeCluster, parLapply) import::into("imports:parallel", makeCluster, parLapply, .from = parallel)
import::from(parallel, makeCluster, parLapply) import::into("imports:parallel", makeCluster, parLapply, .from = parallel)
This is an alternative mechanism for importing objects from
packages. The syntax allows for importing multiple objects from a package
with a single command in an expressive way. The import
package bridges
some of the gap between using library
(or require
) and direct
(single-object) imports. Furthermore the imported objects are not placed in
the current environment (although possible), but in a named entry in the
search path.
This package is not intended for use with library
. It is named to make
calls like import::from(pkg, fun1, fun2)
expressive. Using the import
functions complements the standard use of library(pkg)
(when most objects
are needed, and context is clear) and obj <- pkg::obj
(when only a single
object is needed).
Stefan Milton Bache
For usage instructions and examples, see from
, into
, or
here
.
Helpful links: