utilities {inline} | R Documentation |
writeDynLib
saves the DLL and the CFunc or CFuncList object as
generated by cfunction; readDynLib
loads it.
The print
and code
methods respectively print the entire
object or the code parts.
writeDynLib(x, file) readDynLib(file)
x |
A |
file |
base name of the file to write the object to or to read from.
Two files will be saved, one for the shared object or DLL (extension |
Both the CFunc or CFuncList object and the shared object or DLL are saved,
in two files; the first has extension CFunc
; the second so
or
DLL
, depending on the operating system used.
When reading, both files are loaded, and the compiled function address added to the object.
Function readDynLib
returns a CFunc
or CFuncList
object.
Method print(x, ...)
prints the entire object x
Method code(x, linenumbers = TRUE, ...)
prints the code only
signature(x)
The CFunc
or CFuncList
object as generated by
cfunction
.
linenumbers
If TRUE
all code lines will be numbered.
The code of a CFunc
or CFuncList
object x
can be extracted
(rather than printed), using:
x@code
.
To write the code to a file (here called "fn"
),
without the new-line character "\n"
:
write (strsplit(x, "\n")[[1]], file = "fn")
Karline Soetaert
x <- as.numeric(1:10) n <- as.integer(10) code <- " integer i do 1 i=1, n(1) 1 x(i) = x(i)**3 " cubefn <- cfunction(signature(n="integer", x="numeric"), code, convention=".Fortran") code(cubefn) cubefn(n, x)$x ## Not run: fname <- tempfile() writeDynLib(cubefn, file = fname) # load and assign different name to object cfn <- readDynLib(fname) print(cfn) cfn(2, 1:2) ## End(Not run)