Expand description
Embeds a a single R process
Using R’s C-API requires the embedding of the R runtime.
Thus, when using bindings in libR-sys
, it is necessary that
either the a R process is the caller, or that the process instantiates
an accompanying R process. Otherwise, a run-time error occurs e.g.
(signal: 11, SIGSEGV: invalid memory reference)
or
Caused by:
process didn't exit successfully: `/extendr/tests/extendrtest/target/debug/deps/extendrtest-59155c3c146ae614` (signal: 11, SIGSEGV: invalid memory reference)
§Testing
Within tests, one must use test!
or with_r
as a wrapper around
code that uses the R runtime, e.g.
#[test]
fn testing_r_code() {
with_r(|| {
});
}
Similarly with test!
that is available in extendr_api
, one may
#[test]
fn testing_r_code() {
test! {
};
}
The advantage of test!
is that it allows the use of ?
in test code, while
with_r
is not macro-based, thus code formatter rustfmt
and rust LSPs (Rust Analyzer, Rust Rover, etc.)
works within with_r
without any problems.
§Binaries
In a binary program, one may use start_r
directly in the main
-function.
There is no end_r
, as we terminate the R process setup, when the parent
process terminates.
Modules§
Macros§
- cstr_
mut 🔒
Statics§
- START_R 🔒
Functions§
- end_r 🔒Close down the R interpreter. Note you won’t be able to Restart it, so use with care or not at all.
- Ensures that an embedded R instance is present when evaluating
f
.