Rev 71956 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/utils/man/globalVariables.Rd% Part of the R package, https://www.R-project.org% Copyright 2012-2017 R Core Team% Distributed under GPL 2 or later\name{globalVariables}\alias{globalVariables}\alias{suppressForeignCheck}\title{Declarations Used in Checking a Package}\description{For \code{globalVariables}, the names supplied are of functions orother objects that should be regarded as defined globally when the\code{check} tool is applied to this package. The call to\code{globalVariables} will be included in the package's source.Repeated calls in the same package accumulate the names of theglobal variables.Typical examples are the fields and methods in reference classes,which appear to be global objects to \code{codetools}.(This case is handled automatically by \code{\link{setRefClass}()} andfriends, using the supplied field and method names.)For \code{suppressForeignCheck}, the names supplied are of variablesused as \code{.NAME} in foreign function calls which should not bechecked by \code{\link{checkFF}(registration = TRUE)}. Without thisdeclaration, expressions other than simple character strings areassumed to evaluate to registered native symbol objects. The type ofcall (\code{.Call}, \code{.External}, etc.) and argument counts willbe checked. With this declaration, checks on those names will usuallybe suppressed. (If the code uses an expression that should only beevaluated at runtime, the message can be suppressed by wrapping it ina \code{\link{dontCheck}} function call, or by saving it to a localvariable, and suppressing messages about that variable. See theexample below.)}\usage{globalVariables(names, package, add = TRUE)suppressForeignCheck(names, package, add = TRUE)}\arguments{\item{names}{The character vector of object names. If omitted, the current list ofglobal variables declared in the package will be returned, unchanged.}\item{package}{The relevant package, usually the character string name of the packagebut optionally its corresponding namespace environment.When the call to \code{globalVariables} or\code{suppressForeignCheck} comes in the package's source file,the argument is normally omitted, as in the example below.}\item{add}{Should the contents of \code{names} be added to the current globalvariables or replace it?}}\details{The lists of declared global variables and native symbol objects arestored in a metadata object in the package's namespace, assuming the\code{globalVariables} or \code{suppressForeignCheck} call(s) occuras top-level calls in the package's source code.The check command, as implemented in package \code{tools}, queriesthe list before checking the \R{} source code in the package forpossible problems.\code{globalVariables} was introduced in \R 2.15.1 and\code{suppressForeignCheck} was introduced in \R 3.1.0 so bothshould be used conditionally: see the example.}\value{\code{globalVariables} returns the current list of declared globalvariables, possibly modified by this call.\code{suppressForeignCheck} returns the current list of nativesymbol objects which are not to be checked.}\author{John Chambers and Duncan Murdoch}\note{The global variables list really belongs to a restricted scope (afunction or a group of method definitions, for example) rather thanthe package as a whole. However, implementing finer control wouldrequire changes in \code{check} and/or in \code{codetools}, so in thisversion the information is stored at the package level.}\seealso{\code{dontCheck}.}\examples{\dontrun{## 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:if(getRversion() >= "2.15.1") utils::globalVariables(c(".obj1", "obj2"))## To suppress messages about a run-time calculated native symbol,## save it to a local variable.## At top level, put this:if(getRversion() >= "3.1.0") utils::suppressForeignCheck("localvariable")## Within your function, do the call like this:localvariable <- if (condition) entry1 else entry2.Call(localvariable, 1, 2, 3)## HOWEVER, it is much better practice to write code## that can be checked thoroughly, e.g.if(condition) .Call(entry1, 1, 2, 3) else .Call(entry2, 1, 2, 3)}}\keyword{ packages }