
Last chance! 50% off unlimited learning
Sale ends in
moveDLL
moves the DLL used by a compiled function to a user defined
location.
writeCFunc
saves a CFunc
object after the DLL has been moved to
the desired location using moveDLL
.
readCFunc
reads a CFunc
object that has been saved using
writeCFunc
.
The print
and code
methods respectively print the entire
object or only the code parts.
moveDLL(x, ...)
# S4 method for CFunc
moveDLL(x, name, directory, unload = FALSE, overwrite = FALSE, verbose = FALSE)writeCFunc(x, file)
readCFunc(file)
# S4 method for CFunc
print(x)
# S4 method for CFuncList
print(x)
# S4 method for CFunc
code(x, linenumbers = TRUE)
# S4 method for CFuncList
code(x, linenumbers = TRUE)
Function readDynLib
returns a CFunc
object.
Function writeDynLib
returns the name of the .CFunc
file that
was created.
A CFunc
or CFuncList
object as created by cfunction
The base of the file name that the DLL should be moved to. The file name extension will depend on the operating system used
The directory that the DLL should be written to
In case the new path constructed from name
and
directory
points to a loaded DLL, should we unload it?
In case there is a file at the new path constructed from
name
and directory
should we overwrite that file?
Should we print a message stating where the DLL was copied if the operation was successful?
The file path for writing and reading the object generated by
cfunction
. Consider using a file name extension like
.rda
or .RData
to indicate that this is a serialized
R object.
If TRUE
all code lines will be numbered.
May be used in future methods
Karline Soetaert and Johannes Ranke
If you move the DLL to a user defined location with moveDLL
, this will
keep an on-disk copy of the DLL which will prevent it from being lost at
session termination - unless written to the session tempdir
.
Saving and reloading the CFunc
object with standard tools like
save
or saveRDS
will still loose the pointer to
the DLL. However, when the DLL has been moved using moveDLL
,
CFunc
objects can be saved by writeCFunc
and restored by
readCFunc
.
getDynLib
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
if (FALSE) {
# The following code is exempted from the automated tests of example code, as
# it writes to the users home directory.
# The following writes the DLL, e.g. cubefn.so on Linux/Unix or cubefn.dll
# on Windows
moveDLL(cubefn, name = "cubefn", directory = "~")
path <- file.path("~", "cubefn.rda")
writeCFunc(cubefn, path)
rm(cubefn)
# Now you can start a fresh R session and load the function
library(inline)
path <- file.path("~", "cubefn.rda")
cfn <- readCFunc(path)
cfn(3, 1:3)$x
}
Run the code above in your browser using DataLab