Description Usage Arguments Value Author(s) References See Also Examples
This function accepts a resolved description of a C routine and generates the R code that will invoke that routine by coercing any arguments to the correct type and passing control the native routine. It then converts the result back to an R object.
The code can use a closure to store the address of the native symbol and also the call interface (CIF) object describing the routine for the FFI library.
1 2 | createRFunc(routine, name = routine$name, useGlobalCIF = useClosure,
useClosure = TRUE, returnInputs = NA)
|
routine |
a description of the C routine, obtained via
|
name |
the name of the C routine |
useGlobalCIF |
a logical value indicating whether to use a global
variable to store the CIF for this routine, or to inline the CIF
creation code or, if |
useClosure |
a logical value indicating whether to create a separate environment for this function in which the address of the C routine, the CIF and other objects that are used across different calls to this new function cab be stored |
returnInputs |
the default value for the |
A character vector containing R code to create a function
Duncan Temple Lang
The RGCCTranslationUnit package
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | tu.file = system.file("TU", "utsname", "utsname.c.001t.tu", package = "RGCCTUFFI")
tu = parseTU(tu.file)
r = getRoutines(tu)
r.uname = resolveType(r$uname, tu)
code = createRFunc(r.uname, returnInputs = "FALSE")
ds = getDataStructures(tu)
ds.utsname = resolveType(ds$utsname, tu)
scode = defStructClass(ds.utsname)
define(list(code, scode))
u = utsnamePtr()
uname(u)
names(u)
u[]
u$sysname
################
# Alternatively, we can use genTUInterface() to do everything
# for us in a single call. But we lose some control, e.g.
# setting the returnInputs.
code = genTUInterface(tu.file, pattern = "utsname|uname")
# now we can evaluate/load/define the code in this R session
# including the uname() function.
define(code)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.