Native C types and bindings of libR.
First, add the following to your Cargo.toml:
toml
[dependencies]
libr = 0.1
Next, add this to your crate root:
rust
extern crate libr;
The primary purpose of this crate is to provide an easily
interface for embedding R functions. This include type
definitions (e.g. SEXP
), constants(e.g. PI
) as well as
function headers(e.g. Rf_initEmbeddedR
)
The library now support 64bit Linux only, for the case I have no idea to how to test it in other system. I'm a newer in Rust, so it's so welcome for help and suggestions.
```rust extern crate libr; use std::env; use std::ffi::CString; use libr::embedded::RfinitializeR; use libr::interface::*;
fn main() {
if let Err() = env::var("RHOME") {
panic!("Rembedded test need RHOME be setted");
}
let args = vec!["R", "--no-save"];
let mut args = args.intoiter()
.map(|arg|
CString::new(arg.asbytes()).unwrap().intoraw())
.collect::
See details in math.
```rust extern crate libr; use libr::math::R_pow;
fn main() { asserteq!(unsafe { Rpow(2., 3.) }, 8.); } ```
See details documents in embedded module.
```rust extern crate libr; use std::env; use std::ffi::CString;
use libr::internals::*; use libr::embedded as Rembedded; use libr::ext::parse::{ParseStatus, R_ParseVector};
fn main() { if let Err() = env::var("RHOME") { panic!("Rembedded test need RHOME be setted"); } let mut s = Box::new(vec![CString::new("R").unwrap().intoraw(), CString::new("--quiet").unwrap().intoraw(), CString::new("--no-save").unwrap().intoraw()]); unsafe { Rembedded::RfinitEmbeddedR(s.len() as i32, s.asmutptr()); // Plot let mut status = ParseStatus::PARSEOK; let mut haderror = 0; let tmp = Rfprotect(RfmkString(CString::new("{pdf(\"03-plot.pdf\"); plot(1:10, \ pch=\"+\"); print(1:10)}") .unwrap() .intoraw())); let e = Rfprotect(RParseVector(tmp, 1, &mut status, RNilValue)); RfPrintValue(e); RtryEval(VECTORELT(e, 0), RGlobalEnv, &mut haderror); Rfunprotect(2); Rembedded::RfendEmbeddedR(0); } } ```