Skip to content

package question

2 messages · Christian Lederer, Brian Ripley

#
Dear R-Gurus,

is it possible, to define variables, which are only
visible to functions belonging to a certain package?
(For a certain package i would like to have something
similar to static variables in C, which are only visible
to functions defined in the same source file.)

In the documentation (``Writing R Extensions") i found
nothing appropriate.

Christian :-)
#
Look more closely at the section on `Package name spaces'.

  R has a name space management system for packages. This system allows
  the package writer to specify which variables in the package should be
  exported to make them available to package users ....

Alternatively, you can manage this yourself by using lexical scope:
if you define variables and functions in a local() block (and make sure 
the functions are visible) the variables will be visible only to those 
functions.  There are examples of that in the source file 
src/library/base/R/zdynvars.R (and elsewhere).
On Sun, 25 Jan 2004, Christian Lederer wrote: