#include <array>
#include <vector>
r.
Execute(
"print(version$version.string)");
double std_dev_r =
r.
Eval(
"sd(rnorm(10000))");
std::vector<double>
v =
r.
Eval(
"rnorm(10000)");
std::cout << "standard deviation from R = " << std_dev_r << std::endl;
std::cout << "standard deviation from ROOT = " << std_dev_root << std::endl;
Error(
"ROOT-R-Example",
"Different std-dev found");
r <<
"mat<-matrix(c(1,2,3,4,5,6),2,3,byrow=TRUE)";
std::array<double,6>
a =
r.
Eval(
"seq(1:6)");
Error(
"ROOT-R-Example",
"Different matrix found");
m2.Print();
}
std::vector<double> v_root{1,2,3,4,5,6,7,8};
bool isEqual =
r.
Eval(
"prod(v==v2)");
if (!isEqual) {
Error(
"ROOT-R-Example",
"Different vector created");
}
r <<
"y<-gaus_pdf(0,1,1)";
std::cout << "Function gaussian(0,1,1) evaluated in R = " << value_r << std::endl;
std::cout << "Function gaussian(0,1,1) evaluated in ROOT = " << value_root << std::endl;
if (value_r != value_root)
Error(
"ROOT-R-Example",
"Different function value found in r = %f and ROOT = %f", value_r, value_root);
}
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
ROOT R was implemented using the R Project library and the modules Rcpp and RInside
void Execute(const TString &code)
Method to eval R code.
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.
double normal_pdf(double x, double sigma=1, double x0=0)
Probability density function of the normal (Gaussian) distribution.
Bool_t AreEqualAbs(Double_t af, Double_t bf, Double_t epsilon)
Double_t StdDev(Long64_t n, const T *a, const Double_t *w=0)