Title: | XPtr Add-Ons for 'Rcpp' |
---|---|
Description: | Provides the means to compile user-supplied C++ functions with 'Rcpp' and retrieve an 'XPtr' that can be passed to other C++ components. |
Authors: | Iñaki Ucar [aut, cph, cre] |
Maintainer: | Iñaki Ucar <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2.1 |
Built: | 2024-11-07 05:42:51 UTC |
Source: | https://github.com/Enchufa2/RcppXPtrUtils |
XPtr
's SignatureCheck the signature (i.e., arguments and return type) of the output of
cppXPtr
, which is an external pointer wrapped in an object of
class XPtr
. If the user-supplied C++ function does not match the
signature, the wrapper throws an informative error.
checkXPtr(ptr, type, args = character(), call. = TRUE)
checkXPtr(ptr, type, args = character(), call. = TRUE)
ptr |
an object of class |
type |
the return type. |
args |
a list of argument types. |
call. |
logical, indicating if the call should become part of the error message. |
# takes time to compile ptr <- cppXPtr("double foo(int a, double b) { return a + b; }") checkXPtr(ptr, "double", c("int", "double")) # returns silently try(checkXPtr(ptr, "int", c("double", "std::string"))) # throws error
# takes time to compile ptr <- cppXPtr("double foo(int a, double b) { return a + b; }") checkXPtr(ptr, "double", c("int", "double")) # returns silently try(checkXPtr(ptr, "int", c("double", "std::string"))) # throws error
XPtr
with a C++ ImplementationDynamically define an XPtr
with C++ source code. Compiles and links a shared
library with bindings to the C++ function using cppFunction
,
then returns an XPtr
that points to the function and can be used to be
plugged into another C++ backend.
cppXPtr( code, depends = character(), plugins = character(), includes = character(), rebuild = FALSE, cacheDir = getOption("rcpp.cache.dir", tempdir()), showOutput = verbose, verbose = getOption("verbose") )
cppXPtr( code, depends = character(), plugins = character(), includes = character(), rebuild = FALSE, cacheDir = getOption("rcpp.cache.dir", tempdir()), showOutput = verbose, verbose = getOption("verbose") )
code |
Source code for the function definition. |
depends |
Character vector of packages that the compilation depends on. Each package listed will first be queried for an inline plugin to determine header files to include. If no plugin is defined for the package then a header file based the package's name (e.g. |
plugins |
Character vector of inline plugins to use for the compilation. |
includes |
Character vector of user includes (inserted after the includes provided by |
rebuild |
Force a rebuild of the shared library. |
cacheDir |
Directory to use for caching shared libraries. If the underlying code passed to |
showOutput |
|
verbose |
|
An object of class XPtr
that points to the compiled function.
# takes time to compile ptr <- cppXPtr("double foo(int a, double b) { return a + b; }") class(ptr) print(ptr)
# takes time to compile ptr <- cppXPtr("double foo(int a, double b) { return a + b; }") class(ptr) print(ptr)