| Title: | extend cxxfunction by saving the dynamic shared objects |
|---|---|
| Description: | extend cxxfunction by saving the dynamic shared objects for reusing across R sessions |
| Authors: | Jiqiang Guo <[email protected]> |
| Maintainer: | Jiqiang Guo <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.2 |
| Built: | 2026-05-24 07:56:38 UTC |
| Source: | https://github.com/maverickg/cxxfunplus |
The cxxfunction function in inline could not save
the dynamic shared objects (DSO) created in a session.
We provide a mechanism to save the DSO's if for
example, save.image is called.
Instead of calling cxxfunction in inline, call cxxfunctionplus
in this package, from which an S4 class of cxxdso is returned.
We could use generic function grab.cxxfun of class cxxdso
to retrieve the functions typically returned by cxxfunction.
Jiqiang Guo <[email protected]>
Maintainer: Jiqiang Guo <[email protected]>
"cxxdso"
An S4 class for saving the dynamic shared objects created on the fly
Objects can be created by calls of cxxfunctionplus.
sig:Object of class "list" The signatures of functions defined.
dso_saved:Object of class "logical" Whether to save the DSO or not.
dso_filename:Object of class "character" The original file name for the DSO when it is created (no extension).
system:The operating system where the object is created.
.MISC:Object of class "environment" An environment to
save the functions returned by cxxfunction with
name cxxfun, the last full path for the DSO with
name dso_last_path, and the vector of raw
for saving the binary dynamic shared object (DSO) with
name dso_bin.
signature(x = "cxxdso"): Print a summary of the object.
signature(object = "cxxdso"): Return the function objects contained.
signature(object = "cxxdso"): Tell if the DSO (DLL) is loaded.
signature(x = "cxxdso"): Obtain the DLL associated.
getDynLib, grab_cxxfun, and
cxxfunctionplus
showClass("cxxdso")showClass("cxxdso")
cxxdso from C++ codeThis is a wrap-up of function cxxfunction in package inline.
Additionally, this function returns an object of class cxxdso,
which could be saved and reused across R sessions. All arguments except
save_dso are passed to function cxxfunction.
cxxfunctionplus(sig = character(), body = character(), plugin = "default", includes = "", settings = getPlugin(plugin), save_dso = FALSE, ..., verbose = FALSE)cxxfunctionplus(sig = character(), body = character(), plugin = "default", includes = "", settings = getPlugin(plugin), save_dso = FALSE, ..., verbose = FALSE)
sig |
Signature of the function. A named character vector. |
body |
A character vector with C++ code to include in the body of the compiled C++ function. |
plugin |
Name of the plugin to use. See |
includes |
User includes, inserted after the includes provided by the plugin. |
settings |
Result of the call to the plugin. |
save_dso |
Determine whether to save the compiled code (DSO); defaults to |
... |
Further arguments to the plugin. |
verbose |
verbose output. |
An object of S4 class cxxdso.
cxxfunction and cxxdso
## Not run: src <- ' return ScalarReal(INTEGER(x)[0] * REAL(y)[0]);' dso <- cxxfunctionplus(signature(x = "integer", y = "numeric"), src) show(dso) ## End(Not run)## Not run: src <- ' return ScalarReal(INTEGER(x)[0] * REAL(y)[0]);' dso <- cxxfunctionplus(signature(x = "integer", y = "numeric"), src) show(dso) ## End(Not run)
cxxdso
The getDynLib function retrieves the dynamic library (or DLL)
associated with objects of class cxxdso generated by
cxxfunctionplus
signature(x = "cxxdso")Retrieves the dynamic
library associated with the cxxdso objects generated by
cxxfunctionplus.
getLoadedDLLs, dyn.load,
cxxdso, and
getDynLib in inline
## Not run: dso <- cxxfunctionplus(signature(), "return R_NilValue;") dll <- getDynLib(dso) ## End(Not run)## Not run: dso <- cxxfunctionplus(signature(), "return R_NilValue;") dll <- getDynLib(dso) ## End(Not run)
cxxdso
The grab_cxxfun function retrieves the function object
associated with objects of class cxxdso generated by
cxxfunctionplus
signature(x = "cxxdso")Retrieves the function object
associated with the cxxdso objects generated by
cxxfunctionplus.
cxxfunctionplus, cxxdso
## Not run: dso <- cxxfunctionplus(signature(), "return R_NilValue;") fx <- grab_cxxfun(dso) fx() ## End(Not run)## Not run: dso <- cxxfunctionplus(signature(), "return R_NilValue;") fx <- grab_cxxfun(dso) fx() ## End(Not run)
cxxdso object is loadedThe is_dso_loaded function tell if the dynamic shared object (DSO, or DLL) in
an object of cxxdso, created by function cxxfunctionplus,
is loaded.
signature(x = "cxxdso")Tell if a cxxdso object is
loaded in the sense that the contained DSO is loaded or not.
## Not run: dso <- cxxfunctionplus(signature(), "return R_NilValue ;") print(is_dso_loaded(dso)) ## End(Not run)## Not run: dso <- cxxfunctionplus(signature(), "return R_NilValue ;") print(is_dso_loaded(dso)) ## End(Not run)
cxxfunction
points to NULLThe function object returned by cxxfunction cannot be
saved across R sessions. This function can be used to see
if we still have a valid function object. Also this function
can be used for functions returned by grab_cxxfun
of S4 class cxxdso since these functions are essentially
created by cxxfunction or similarly.
is_null_cxxfun(cx)is_null_cxxfun(cx)
cx |
A function of class |
R could not save the function objects that point to dynamically loaded
functions, especially for those function created on the fly using package
inline at least for one reason that those DSO's are deleted after
quitting R. So it is always safe to tell if it is valid before call functions
created by cxxfunction.
Logical: TRUE null pointer; FALSE, not
null, this function can still be called.