makeImports: Write Import Directives for a Package

Description Usage Arguments Details Value

Description

Import directives suitable for all non-local functions called from the specified package will be written to the output (standard output by default), if the function is found in a package currently attached to the session.

Usage

1
makeImports(package, missingOnly = TRUE, output = stdout())

Arguments

package

Either the character string name of the package or an environment. In the first case, searches will start in the namespace of the environment; in the second they will start in the supplied argument. The character string version is usually what you want. See Details.

missingOnly

If TRUE, only globals not in the parent environment will be searched for: see the Details for what this means.

output

A connection, standard output by default. The function doesn't currently handle file names, so you need to open the connection before the call.

Details

The function starts with the namespace of the packaage. It uses 'codetools::findGlobals()' to get a list of non-local references. If 'missingOnly' is 'TRUE', any of those found in the parent of the namespace (the imports environment) are omitted. The chain of parent environments is then searched for corresponding function definitions. For all found in a package, 'importFrom()' directives are constructed. These are printed to the 'output' connection (standard output by default), along with comments reporting those references not found and those found, but not in a package.

Two details to note. The imports environment will contain those objects appearing in imports directives in the current NAMESPACE file. Because the chain of parent environments includes the search path, the relevant packages should be attached in the intended order before calling 'makeImports()'.

Also, the current implementation does nothing special about calls in the form 'package::f()', so it could give erroneous imports for those functions. Also, it relies on the 'findGlobals()' function, which cannot always find all global references.

Value

A list of all the global references, split by package name, is returned invisibly.


johnmchambers/XRtools documentation built on May 19, 2019, 5:16 p.m.