dyn.open
function makes shared
libraries available for use by S-PLUS functions. The shared
libraries with which S-PLUS is linked are available by
default, without any action on your part, so you may not
need to use this function to use symbols defined in
"standard" libraries. Use
dyn.close
to close an open library that you have no further need for.
dyn.open(file, initialize="") dyn.close(file)
dyn.open
, the requested library is
opened and dynamically linked to the current S-PLUS session.
For
dyn.close
, the requested library
is closed.
In most cases, the shared libraries you need
(typically, a S-PLUS chapter's
S.so
file) is opened automatically when you attach the
appropriate database. You will typically use
dyn.open
to open
shared libraries that exist in unattached chapters
or elsewhere on your system.
If you change a library
that has already been loaded with
dyn.open
,
call
dyn.close
on it
before calling
dyn.open
or nothing will happen. If you change a library
that has been automatically loaded with
attach
or
library
then use
synchronize(n)
where
n
is the database identifier
to reload the library.
Note that you may load only shared libraries and
not archives (.a files).
.C
and
.Fortran
functions.
With the following C code, kept in the file mylog.c, % cat mylog.c # include "S_engine.h" # include <math.h> void # if defined(__STDC__) mylog(double *x, long *n) # else mylog(x, n) double *x ; long *n ; # endif { long i ; if (*n < 0) { PROBLEM "n (=%ld) should not be negative", *n RECOVER(NULL_ENTRY) ; } for (i=0 ; i<*n ; i++) x[i] = log(x[i]) ; } we can make a shared library with the following UNIX commands: Splus CHAPTER mylog.c Splus make and once in S-PLUS can load it as follows: dyn.open("S.so") and use it with .C("mylog", c(45, 45*exp(1)), as.integer(2))[[1]] # [1] 3.806662 4.806662 If we want to change the C code, say to give the negative of the log, we must unload the shared object with dyn.close, edit the C code, use make again to make the shared library, then reload it using the dyn.open so that .C() will find the newly redefined function: dyn.close("S.so") !vi mylog.c !Splus make dyn.open("S.so") .C("mylog", c(45, 45*exp(1)), as.integer(2))[[1]] # [1] -3.806662 -4.806662