9 r.
Execute(
"print(version$version.string)");
13 double std_dev_r =
r.
Eval(
"sd(rnorm(1000))");
14 std::vector<double>
v =
r.
Eval(
"rnorm(1000)");
16 std::cout <<
"standard deviation from R = " << std_dev_r << std::endl;
17 std::cout <<
"standard deviation from ROOT = " << std_dev_root << std::endl;
19 Error(
"ROOT-R-Example",
"Different std-dev found");
22 r <<
"mat<-matrix(c(1,2,3,4,5,6),2,3,byrow=TRUE)";
24 std::array<double,6>
a =
r.
Eval(
"seq(1:6)");
28 Error(
"ROOT-R-Example",
"Different matrix found");
34 std::vector<double> v_root{1,2,3,4,5,6,7,8};
37 bool isEqual =
r.
Eval(
"prod(v==v2)");
39 Error(
"ROOT-R-Example",
"Different vector created");
48 r <<
"y<-gaus_pdf(0,1,1)";
49 double value_r =
r[
"y"];
51 std::cout <<
"Function gaussian(0,1,1) evaluated in R = " << value_r << std::endl;
52 std::cout <<
"Function gaussian(0,1,1) evaluated in ROOT = " << value_root << std::endl;
53 if (value_r != value_root)
54 Error(
"ROOT-R-Example",
"Different function value forund in r = %f and ROOT = %f", value_r, value_root);
void Execute(const TString &code)
Method to eval R code.
double normal_pdf(double x, double sigma=1, double x0=0)
Probability density function of the normal (Gaussian) distribution.
void Error(const char *location, const char *msgfmt,...)
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
void Print(Option_t *name="") const
Print the matrix as a table of elements.
Double_t StdDev(Long64_t n, const T *a, const Double_t *w=0)
static TRInterface & Instance()
static method to get an TRInterface instance reference
Int_t Eval(const TString &code, TRObject &ans)
Method to eval R code and you get the result in a reference to TRObject.