extern crate libc;
extern crate libr;
use std::ptr;
use std::env;
use std::ffi::{CStr, CString};

use libr::ffi::internals::*;
use libr::ffi::embedded::{self, Rf_endEmbeddedR, Rf_initEmbeddedR};
use libr::ffi::ext::parse::{ParseStatus, R_ParseVector};

fn main() {
    if let Err(_) = env::var("R_HOME") {
        panic!("Rembedded test need R_HOME be setted");
    }

    let mut s = Box::new(vec![CString::new("R").unwrap().into_raw(),
                              CString::new("--quiet").unwrap().into_raw(),
                              CString::new("--no-save").unwrap().into_raw()]);
    unsafe {
        embedded::Rf_initEmbeddedR(s.len() as i32, s.as_mut_ptr());
        // Plot
        let mut status = ParseStatus::PARSE_OK;
        let mut had_error: libc::c_int = 0;
        let mut tmp = Rf_protect(Rf_mkString(CString::new("{pdf(\"03-plot.pdf\"); plot(1:10, pch=\"+\"); print(1:10)}").unwrap().into_raw()));
        let mut e = Rf_protect(R_ParseVector(tmp, 1, &mut status, R_NilValue));
        Rf_PrintValue(e);
        R_tryEval(VECTOR_ELT(e,0), R_GlobalEnv, &mut had_error);
        Rf_unprotect(2);
        embedded::Rf_endEmbeddedR(0);
    }
}

Add example for parse and eval R code from string
Add example for parse and eval R code from string
