Description Usage Arguments Value Author(s) Examples
Compile a shared library using R CMD SHLIB
. Options exist
for converting the compiler output to R messages, warnings and
errors.
1 2 3 4 |
filenames |
Vector of filenames |
verbose |
Be verbose (print compiler output to screen) |
output |
Name to use for the file output (passed to
|
clean |
Clean intermediate targets (passed to |
preclean |
Clean intermediate targets before running (passed
to |
dry_run |
Don't run anything, but print commands (passed to
|
debug |
Create a debug dll (windows only; passed to
|
stop_on_error |
If an error in compilation is thrown, throw
an error (TRUE by default). If set to |
warn_on_warning |
If a the compiler returns a warning, issue an R warning (TRUE by default). |
chdir |
One of |
use_colour |
Use ANSI escape colours (via the |
Invisibly, A list with four elements: success
- a
logical indicating if the command was successful (this can only
be FALSE
if stop_on_error
is FALSE
),
output
- an object of class compiler_output
containing compiler output, dll
- the path to the created
shared library, or NA_character_
if the command failed,
and base
- the dll name without leading path or extension
(suitable to use as the PACKAGE
argument to
.Call
). If the command changed directory then the
normalized (and therefore absolute) path to the dll is returned.
Rich FitzJohn
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # A small piece of C code saved as add.c within a temporary directory:
txt <- c("#include <R.h>",
"#include <Rinternals.h>",
"SEXP add2(SEXP a, SEXP b) {",
" return ScalarReal(REAL(a)[0] + REAL(b)[0]);",
"}")
path <- tempfile()
dir.create(path)
filename <- file.path(path, "add.c")
writeLines(txt, filename)
# Compile the object:
res <- rcmdshlib::shlib(filename)
res
# Load it into R:
dyn.load(res$dll)
# And call it
.Call("add2", pi, 1, PACKAGE = res$base)
# Cleanup
dyn.unload(res$dll)
unlink(path, recursive = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.