writeDynLib saves the DLL and the CFunc or CFuncList object as
generated by cfunction;
readDynLib loads it.
code methods respectively print the entire
object or the code parts.
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
DLL, depending on the operating system used.
When reading, both files are loaded, and the compiled function address added to the object.
readDynLib returns a
print(x, ...) prints the entire object
signature(x = "CFunc")
Prints the CFunc object
cfunction, including the code that generated it.
signature(x = "CFuncList")
Print all CFunc objects
cfunction, including the code that generated them.
code(x, linenumbers = TRUE, ...) prints the code only
CFuncList object as generated by
TRUE all code lines will be numbered.
The code of a
x can be extracted
(rather than printed), using:
To write the code to a file (here called
without the new-line character
write (strsplit(x, "\n")[], file = "fn")
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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)