library(name) library.dynam("name.so") require(name, quietly=FALSE) provide(name) .Libraries .Provided
name
|
The name of a library.
With no argument library will print out a list
of available libraries.
|
quietly
|
With quietly=TRUE a warning will not be printed
if the library cannot be found.
|
library
and require
both load a library.
require
is designed for use inside other functions;
it returns FALSE
and optionally gives a warning,
rather than giving an error, if the library does not exist.
Both functions check and update the list of currently
loaded libraries stored in .Libraries
and do not
reload code that is already loaded, require
also checks
the list .Provided
. provide
allows code to register services
that it provides. The argument is stored in the list .Provided
.
provide
returns FALSE
if the name was already present in
.Provided
or library
.
The main use for provide
is when multiple libraries share code.
This is most likely when the code implements features present in S(-PLUS)
but not in R. For example, the spline functions ns
,
bs
and so on are not included in the R distribution.
A library that contains these functions can use provide(splines)
to register this fact. Another library that needs the functions
can execute require(splines)
rather than library(splines)
to load the spline library only if their functionality is not already
available.
library()
with no argument gives a list of available libraries;
provide()
with no argument returns list(.Provided, .Libraries)
.
library.dynam()
loads the specified object file from RHOME/lib
if it has not been loaded already. It is designed to be used inside
a library rather than at the command line.
help(library(name))
prints a list of functions in library "name".
CREATING LIBRARIES
Libraries provide a mechanism for loading optional code and its documentation
as needed. Libraries are compiled and installed from subdirectories
of RHOME/src/library; eda
and mva
are provided as examples.
A library consists of a subdirectory containing a TITLe
and INDEX
file, and subdirectories funs
, man
, src
and src-c
. The TiTLE
file contains a line giving the name
of the library and a brief description. INDEX
contains a line
for each sufficiently interesting function in the library,
giving its name and a description (functions such as print methods
not usually called explicitly might not be included).
The funs
subdirectory contains R code files with names beginning
with lowercase letters. One of these files should use library.dynam()
to load any necessary compiled code.
Source and a Makefile for the compiled code is in src
, and a pure
C
version of the source should be in src-c
. In the common
case when all the source is in C
it may be convenient to make one
of these directories a symbolic link to the other. The Makefile will be
passed various machine-dependent compile and link flags, examples of
which can be seen in the eda
library.
The man
subdirectory should contain R help files for the
functions in the library.
To install a library run make libs
in RHOME/src/library
and
then run etc/lib-installhelp
in RHOME
. This will reinstall
all the libraries.
library
returns the list of loaded libraries;
require
returns a boolean value indicating
whether the required library is available.