globalVariables {utils} | R Documentation

## Declare Variables to be Treated as Global in Checking a Package

### Description

The names supplied are of functions or other objects that should be regarded as defined globally when the `check` tool is applied to this package. The call to `globalVariables` will be included in the package's source. Repeated calls in the same package accumulate the names of the global variables.

Typical examples are the fields and methods in reference classes, which appear to be global objects to `codetools`. (This case is handled automatically by `setRefClass()` and friends, using the supplied field and method names.)

### Usage

    globalVariables(names, package, add = TRUE)

### Arguments

`names` | The character vector of object names. If omitted, the current list of global variables declared in the package will be returned, unchanged.
`package` | The relevant package, usually the character string name of the package but optionally its corresponding namespace environment. When the call to `globalVariables` comes in the package's source file, the argument is normally omitted, as in the example below.
`add` | Should the contents of `names` be added to the current global variables or replace it?

### Details

The list of declared global variables is stored in a metadata object in the package's namespace, assuming the `globalVariables` call(s) occur as top-level calls in the package's source code.

The check command, as implemented in package `utils`, queries the global variables list before checking the R source code in the package for possible problems.

### Value

The current list of declared global variables, possibly modified by this call.

### Note

The global variables list really belongs to a restricted scope (a function or a group of method definitions, for example) rather than the package as a whole. However, implementing finer control would require changes in `check` and/or in `codetools`, so in this version the information is stored at the package level.

### Author(s)

John Chambers

### Examples

    ## Not run:
    ## assume your package has some code that assigns ".obj1" and ".obj2"
    ## but not in a way that codetools can find.  In the same source file
    ## (to remind you that you did it) add:
    utils::globalVariables(c(".obj1", "obj2"))

    ## End(Not run)

[Package utils version 2.15.1 Index]